小编Sma*_*cat的帖子

方法 'scene(_:openURLContexts:)' 没有被调用

在 info.plist 文件中,我配置URL IdentifierURL 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)

iphone custom-scheme-url swift5 ios13

19
推荐指数
3
解决办法
4339
查看次数

标签 统计

custom-scheme-url ×1

ios13 ×1

iphone ×1

swift5 ×1