0

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

    }
Philip Arpin
  • 128
  • 2
  • 14

1 Answers1

0

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];
}
Hilen
  • 761
  • 7
  • 8