gpt4 book ai didi

ios - 条件绑定(bind)的初始化程序必须具有可选类型,而不是 'DynamicLinks'

转载 作者:行者123 更新时间:2023-11-30 11:06:18 25 4
gpt4 key购买 nike

我在构建 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
}

最佳答案

显然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
}

关于ios - 条件绑定(bind)的初始化程序必须具有可选类型,而不是 'DynamicLinks',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52677747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com