ios - 当我从 Scheme Url(Swift 项目)启动应用程序时未调用 openURL
问题描述
当我通过myapp://param1=abc
open url 函数打开我的应用程序时,不会调用它。
正如Apple文档所说,我已经添加了函数didFinishLaunchingWithOptions
并willFinishLaunchingWithOptions
制作它true
,但它仍然没有被调用。应用程序完美打开,但没有调用函数 open url 我无法获取 param1
这是我的AppDelegate
文件:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Here doesn't come! :(
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
知道会发生什么吗?
谢谢!
解决方案
openUrl
方法 in的签名AppDelegate
更新为,
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return true
}
您需要在项目设置的信息选项卡下urlScheme
的URL 类型中添加您的,即
对于 Swift-5 和 iOS-13:
在SceneDelegate.swift
文件中,您需要实现以下方法来处理urlSchemes
,即
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts)
}
推荐阅读
- javascript - 无法解决找不到插件“proposal-class-properties”
- javascript - 将停车标志的颜色更改为蓝色?
- reactjs - 条件渲染,“遇到两个用同一个键的孩子”
- python - 强制最佳拟合线通过一个点
- wordpress - 在自定义 Wordpress API 端点中使用 nonce
- jquery - jQuery 创建和追加元素
- java - 我的应用程序不会从我的 Main 活动切换到我的 Dashboard 活动。这个问题是我的意图还是表现出来的?
- excel - 宏 SaveAs 到任何桌面
- kotlin - Kotest - 生成无重复的详尽对象排列
- at-command - SIM5300E 屏蔽 COM 端口上的奇怪读数