IOS: Load a View Controller When App is Launched from Browser using url schemes?

烈酒焚心 提交于 2019-12-13 01:26:58

问题


I am new to iPhone developing , My app is based on video conferencing, I have a task where an app should launch from browser using URL schemes. I have done it but problem is when app launched from browser it should load particular view controller. I am using Storyboard. Here is the code which I tried.

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if (!url) {  return NO;
    }

    NSString *URLString = [url absoluteString];
    [[NSUserDefaults standardUserDefaults] setObject:URLString forKey:@"url"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    URLParser *parser = [[URLParser alloc] initWithURLString:URLString];
     username = [parser valueForVariable:@"USERNAME"];
    NSLog(@"%@", username); //b
    sessid = [parser valueForVariable:@"SESSION_ID"];
    NSLog(@"%@", sessid); //(null)
    tokenid = [parser valueForVariable:@"token"];
    NSLog(@"%@", tokenid); //yes
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    ViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"VideoController"];

       return YES;
}

回答1:


This is how I do it..

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    //get parameters
    [self goResetPassword:dict];
    }
    return YES;
}

- (void) goResetPassword:(NSDictionary*) dict{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UINavigationController *root = [[UINavigationController alloc]initWithRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"resetPasswordView"]];
    self.window.rootViewController= root;
    ResetPasswordViewController *vc = (ResetPasswordViewController*)[[root viewControllers] objectAtIndex:0];
    [vc loadData:dict];
}

hope it helps... GL HF




回答2:


According to your comment your initial ViewController is NavigationController. This is how you can push the required ViewController.

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    // same code

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];

// Get instance of initial Viewcontroller from storyboard
UINavigationController *navController = [storyboard instantiateInitialViewController
];
// Get instance of desired viewcontroller
    ViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"VideoController"];
// Push ViewController on to NavigationController
[navController pushViewController:viewController  animated:NO];
       return YES;
}



回答3:


Check It

UIStoryboard *board             = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UINavigationController *nav     = [[UINavigationController alloc] init];

[nav setNavigationBarHidden:NO];

IntroVC *initailView  = [board instantiateViewControllerWithIdentifier:@"Intro"];
[nav pushViewController:initailView animated:YES];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
UIApplication *sharedApplication = [UIApplication sharedApplication];
[sharedApplication unregisterForRemoteNotifications];


来源:https://stackoverflow.com/questions/21325372/ios-load-a-view-controller-when-app-is-launched-from-browser-using-url-schemes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!