应用程序崩溃时,不使用URL Scheme打开并打开

我的应用程序可以在后台打开或运行时使用URL Scheme打开,但是如果我退出应用程序(不在后台或前台运行),然后尝试使用URL Scheme打开它,则会立即崩溃。

从OpenURL到OpenURL的代码:

var url: NSURL = NSURL(string: "lifeguard://emergency")! self.extensionContext?.openURL(url, completionHandler: nil) 

处理url的代码:

 func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool { if (url.host == "emergency") { NSNotificationCenter.defaultCenter().postNotificationName("emergency", object: nil) } return true } 

我也有这个怪物 但是我的情况不一样 经过这个方法

 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.scheme isEqualToString:"your URL"]) { return [[URLManager sharedInstance] handleOpenURL:url]; } return YES; } 

我想要select的视图控制器做一些事情。 所以我试图调用这个:

 - (void)callController { [self performSelector:@selector(performSelectorPushView:) withObject:controller afterDelay:0.0]; } - (void)performSelectorPushView:(UIViewController *)controller { BOOL animated = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive); [yourRootViewController pushViewController:controller animated:animated]; }