ios - 深层链接 URL 方案不调用任何函数(swift)
问题描述
我正在实施深层链接是 iOS。我已经在 Project-Setting->Info->Url type URL Schemes 中配置了 URL Scheme:carwash role:Viewer
当我输入 carwash://something 时,浏览器要求打开应用程序,但在我处理应该发生什么操作的应用程序中没有调用任何内容。
苹果文档说您应该在 AppDelegate 中覆盖应用程序(打开 url),但深度链接会调用它并且应用程序以最后状态打开
application:openURL:options:' 没有被调用
这是我的代码,但不起作用
func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
fatalError()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if let url = launchOptions?[UIApplication.LaunchOptionsKey.url] as? URL {
/// some
fatalError()
}
GMSServices.provideAPIKey("")
return true
}
swift 5 模拟器:iOS 13
解决方案
经过几天与方案网址的斗争,我终于找到了答案。我的模拟器的 iOS 版本是 13 。在 iOS 13 UIApplication 中,打开的 url 没有被调用(至少在我的情况下可能)
您应该覆盖 iOS 13 中可用的 SceneDelegate 中的以下函数:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url{
print(url)
}
}
已编辑:如果用户在您的应用未运行时点击链接,您将不会响应它
您必须实施scene(_:willConnectTo:options:)
以检测选项中的 URLContext:并处理它。
推荐阅读
- reactjs - 在 react-native-devoice-info 中找不到类异常
- flowtype - Flowtype 返回值取决于输入
- angular - 当所有指令都存在时,是什么阻止了组件呈现?
- python - 我希望我的 .py 代码能够全局读取 excel 文件
- javascript - 如何在运行时将文本框值传递给 php?
- java - RecyclerView 点击位置 0 也设置为点击位置 11
- r - 如何打破R中的某些循环
- c - 为什么 getch() 在以很短的延迟调用 halfdelay() 后读取 EOF?
- angular-ui-grid - ui.grid 在 gridApi 上使用 $scope 在 $scope 上遇到错误未定义
- owl - 将时间本体与传感器数据结合使用