iOS Swift 2.3: correct syntax for application restorationHandler?

喜夏-厌秋 提交于 2019-12-11 23:44:35

问题


I am trying to setup Firebase Dynamic Links in my iOS project using Swift 2.3.

When I add this function in the AppDelegate (as reported at the bottom of this page), I get the error:

Unknown attribute 'escaping'

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    guard let dynamicLinks = FIRDynamicLinks.dynamicLinks() else {
       return false
    }
    let handled = dynamicLinks.handleUniversalLink(userActivity.webpageURL!) {
       (dynamiclink, error) in
       // ...
    }
    return handled
}

any idea which is the correct syntax for Swift 2.3?


回答1:


The method which you are using is for swift3, here is the method for swift2.3

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {

}



回答2:


if you want to add restriction on deep link then implement bellow method like this this delegate method call first.

func application(application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool {


    return userActivityType == NSUserActivityTypeBrowsingWeb ? true : false

}

if you want to link which user have click or if you have multiple deep link in single app then want to identify then you can get like this.

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool{
    // pass the url to the handle deep link call
    print(userActivity.webpageURL)
    //NSURLComponents
    return true
}


来源:https://stackoverflow.com/questions/40673319/ios-swift-2-3-correct-syntax-for-application-restorationhandler

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