简体   繁体   中英

Launch inactive app with URL scheme

I was able to add capability to launch my iOS app from URL (ie: myapp://xxxx) if the app is already running. However, if I close the app (crash it) and click on the URL, it only opens the app in the rootView instead of calling the func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool method. Any ideas? In addition, it seems the only way I can test it is on an actual device and close the app, hence I can't use Xcode to debug.

You should use "application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool" function to get url which called to open app, so modify application delegate to become like this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    //any thing need to initialise app
    if let url = launchOptions?[UIApplicationLaunchOptionsURLKey] as? NSURL {
        let sourceApp = launchOptions?[UIApplicationLaunchOptionsSourceApplicationKey] as? String
        let annotation = launchOptions?[UIApplicationLaunchOptionsAnnotationKey] as? AnyObject
        self.application(application, openURL: url, sourceApplication: sourceApp, annotation: annotation)
    }

    return true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM