当没有后台并使用URL Scheme打开时,应用程序崩溃

时间:2014-12-17 03:41:39

标签: ios swift url-scheme

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

来自扩展程序的OpenURL代码:

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

处理网址的代码:

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 个答案:

答案 0 :(得分:0)

我也有这个问题。但我的情况有所不同。这个方法之后

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

我希望选定的视图控制器能够执行某些操作。所以我试着称之为:

- (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];
}
相关问题