Univeral links: Handle universal links clicked within the app

This commit is contained in:
manuroe
2016-04-18 17:53:30 +02:00
parent 9477ae5907
commit 1c6b35b97e
3 changed files with 65 additions and 0 deletions
@@ -1233,6 +1233,41 @@
}
}
- (BOOL)dataSource:(MXKDataSource *)dataSource shouldDoAction:(NSString *)actionIdentifier inCell:(id<MXKCellRendering>)cell userInfo:(NSDictionary *)userInfo defaultValue:(BOOL)defaultValue
{
BOOL shouldDoAction = defaultValue;
if ([actionIdentifier isEqualToString:kMXKRoomBubbleCellShouldInteractWithURL])
{
// Try to catch universal link supported by the app
NSURL *url = userInfo[kMXKRoomBubbleCellUrl];
// Patch: iOS handles URL badly when there are several hash keys ('%23') in the link
// And vector.im links have often several hash keys...
if ([url.host isEqualToString:@"vector.im"])
{
// Replacing the first '%23' occurence into a '#' makes NSURL works correctly
NSString *urlString = url.absoluteString;
NSRange range = [urlString rangeOfString:@"%23"];
if (NSNotFound != range.location)
{
urlString = [urlString stringByReplacingCharactersInRange:range withString:@"#"];
url = [NSURL URLWithString:urlString];
}
// If the link can be open it by the app, let it do
if ([[AppDelegate theDelegate] isUniversalLink:url])
{
shouldDoAction = NO;
[[AppDelegate theDelegate] handleUniversalLinkFragment:url.fragment];
}
}
}
return shouldDoAction;
}
- (void)cancelEventSelection
{
if (self.currentAlert)