App crashes when not backgrounded and opened using URL Scheme

 ̄綄美尐妖づ 提交于 2019-12-10 12:24:44

问题


My Application opens fine using the URL Scheme when it is open or running in the background, but if I quit the app, (not running in background or foreground) and then try to open it using the URL Scheme, it crashes immediately.

Code to OpenURL from Extension:

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

Code to handle 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

    }

回答1:


I have this porblem too. But my situation is different. After this method

- (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;
}

I want the selected view controller to do something. So I try to call this:

- (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];
}


来源:https://stackoverflow.com/questions/27517945/app-crashes-when-not-backgrounded-and-opened-using-url-scheme

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