Jeremy Sh Jeremy Sh - 6 months ago 25
iOS Question

Navigate to specific view with URL Scheme

I added a url scheme newConversation to my info.plist so that when a user clicks on a link in a browser/email it will redirect him to the app. This works perfectly fine.

I was wondering how I can open the app to a specific view controller when clicking this url?

I tried using:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([url.scheme isEqualToString:@"newConversation"]) {
NSLog(@"url schemeeeee");
emailLink = YES;
[self initWindow];
}
return YES;
}


but not getting anywhere with that.

Thanks!

Answer

Your app should only have one scheme (such as myappscheme) registered for your app. Then if you need to handle different actions, you provide more specific URLs with that scheme:

myappscheme:///newConversation
myappscheme:///doSomethingElse

Then you get /newConversation for the URL's path. Then your code becomes:

if ([url.path isEqualToString:@"/newConversation"]) {
} else if ([url.path isEqualToString:@"/doSomethingElse"]) {
}
Comments