在 info.plist 文件中,我配置URL Identifier并URL Scheme成功。我也可以使用自定义 URL 打开应用程序。问题是当应用程序第一次启动该方法时
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)
Run Code Online (Sandbox Code Playgroud)
不叫。
我有一些基于上述方法的依赖功能。所以当应用程序第一次启动时,我在我的应用程序中看不到任何东西。
我还在方法中添加了代码
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
let url = connectionOptions.urlContexts.first?.url
}
Run Code Online (Sandbox Code Playgroud)
但我在这里得到的 url 为零。
但是,如果我的应用程序处于后台模式并且我点击了 URL,那么上述方法调用成功并且相关功能正常工作。以下是我scene(_:openURLContexts:)在sceneDelegate.
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>){
let url = URLContexts.first?.url
let urlString: String = url!.absoluteString
if let urlComponents = URLComponents(string: urlString),let queryItems …Run Code Online (Sandbox Code Playgroud)