[英]URL Opening Swift App - Open Works - Called Function Does NOT work
Hello All – I am a newbie here ... trying to get my first iOS Swift (Xcode 11.2.1 / Swift 5 / iOS 13.2) app to open via URL and process the URL string.大家好 - 我是这里的新手......试图让我的第一个 iOS Swift (Xcode 11.2.1 / Swift 5 / iOS 13.2) 应用程序通过 URL 打开并处理 URL 字符串。 The app opens just fine, but the function (method?) does not appear to be getting called.
应用程序打开得很好,但函数(方法?)似乎没有被调用。 Here's what I've got:
这是我所拥有的:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("Here I iz ... in the URL responding bit.")
print(url)
return true
}
...
That code is in the AppDelegate.swift file in my project.该代码位于我项目的AppDelegate.swift文件中。
And that is what I have in my Info.plist file.这就是我在Info.plist文件中的内容。
I launch via Safari both on-device and in the simulator with confirmevent://HelloWorld
我通过 Safari 在设备上和模拟器中使用
confirmevent://HelloWorld
As I said ... The app is opening, but I do not see any results from my print statements in the Xcode debug area.正如我所说......应用程序正在打开,但我在 Xcode 调试区域中没有看到我的打印语句的任何结果。
In searching other posts they said that I need to use the "Wait for executable to be launched" to attach Xcode to the app, which I have done and it is indeed attaching.在搜索其他帖子时,他们说我需要使用“等待可执行文件启动”将 Xcode 附加到应用程序,我已经完成并且确实附加了。 BUT I notice that none of my dozens of print statements that I have scattered about in my app appear when either when opening via "wait for executable to be launched" option.
但是我注意到,当我通过“等待可执行文件启动”选项打开时,我在应用程序中散布的数十个打印语句中没有一个出现。
Any/All help would be appreciated.任何/所有帮助将不胜感激。 I've spent over 5 hours scouring the web, but all indications are that is should "just work"
我花了 5 多个小时在网上搜索,但所有迹象都表明应该“正常工作”
I just found a solution here: application(...continue userActivity...) method not called in ios 13我刚刚在这里找到了一个解决方案: application(...continue userActivity...) method not called in ios 13
The trick is to also implement the SceneDelegate.swift
functions for Apps with iOS > 13. This function should be called if you open the URL confirmevent://HelloWorld
:诀窍是还为 iOS > 13 的应用程序实现
SceneDelegate.swift
函数。 如果您打开 URL confirmevent://HelloWorld
则应调用此函数:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts.debugDescription)
}
WindowGroup {
SampleView()
.onOpenURL { url in
//this url that was opened by your app
}
}
}
you need to use this function in your appDelegate你需要在你的 appDelegate 中使用这个函数
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL {
print(incomingURL)
}
return false
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.