我是iPhone新手,我的应用程序基于视频会议,我的任务是应用程序应该使用URL方案从浏览器启动。我已经做到了,但问题是当从浏览器启动应用程序时它应该加载特定的视图控制器。我正在使用Storyboard。这是我试过的代码。
- (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;
}
答案 0 :(得分:2)
我就是这样做的。
- (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];
}
希望它有帮助... GL HF
答案 1 :(得分:0)
根据您的评论,您的初始ViewController是NavigationController。这就是你如何推送所需的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;
}
答案 2 :(得分:0)
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];