条件绑定的初始化程序必须具有可选类型,而不是“ DynamicLinks”

时间:2018-10-06 09:45:52

标签: ios swift xcode swift3 firebase-dynamic-links

在构建iOS应用时出现此错误。

我在此处大胆显示的行上显示错误

这是我的代码

@available(iOS 8.0, *)
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    **guard let dynamicLinks = DynamicLinks.dynamicLinks() else {**
        return false
    }
    let handled = dynamicLinks.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
        self.openURL(url: userActivity.webpageURL!)
    }

    if !handled {
        if let url = userActivity.webpageURL?.absoluteString {
            self.openURL(url: URL(string: url)!)
        }
    }
    return handled
}

1 个答案:

答案 0 :(得分:0)

显然DynamicLinks.dynamicLinks()不会产生可选结果。将您的代码更改为此:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

    let dl = DynamicLinks.dynamicLinks()

    let handled = dl.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
        self.openURL(url: userActivity.webpageURL!)
    }

    if !handled {
        if let url = userActivity.webpageURL?.absoluteString {
            self.openURL(url: URL(string: url)!)
        }
    }
    return handled
}