自定义 URL 方案不适用于 Swift 5、Xcode 11

39f*_*edy 8 swift swift5 swiftui

我在我的 Xcode 项目中添加了一个自定义 URL 方案(我使用的是 SwiftUI)。

在此处输入图片说明

在 AppDelagate 文件中,我添加了:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print(url.absoluteString)
        print("work")
        return true
    }
Run Code Online (Sandbox Code Playgroud)

当我在模拟器或物理设备中访问 Safari (sampleurlscheme://) 时,代码没有被执行(即日志不显示等),但它把我带到了应用程序。

有什么我遗漏的或者这可能是一个错误吗?

39f*_*edy 11

看来这是在 SceneDelegate.swift 中使用函数处理的:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)
Run Code Online (Sandbox Code Playgroud)