1

I'm using custom URL scheme to open my app. My code below is used to open a view from the tabbar. But how should I open a specific view.

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

if ([url.host  isEqual: @"main"]) 
{
    UITabBarController *tab = (UITabBarController *)self.window.rootViewController;
    tab.selectedIndex = 0;
}
hatched
  • 795
  • 2
  • 9
  • 34

2 Answers2

1

You need to check url scheme as below :

 if ([[url scheme] isEqualToString:@"main"]) {
       UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
       UITabBarController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarcontroller"]; // if you are use storyboard .
       [self.Window setRootViewController:rootViewController];
    }
KKRocks
  • 8,222
  • 1
  • 18
  • 84
0
if ([[url scheme] isEqualToString:@"main"]) {
       UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
       UITabBarController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarcontroller"]; // if you are use storyboard .
    tab.selectedIndex = 0;
       [self.Window setRootViewController:rootViewController];
    }
Tanvi Jain
  • 917
  • 2
  • 7
  • 19