繁体   English   中英

在xcode 11 beta5和swiftui上进行深层链接

[英]Deep-linking on xcode 11 beta5 and swiftui

我想使用SwiftUI和深层链接,在两个应用之间传递数据。 但这似乎行不通。

我构建了两个小应用程序。 第一个具有文本字段和按钮的应用程序,第二个具有标签和按钮的应用程序。 当我在第一个应用程序中按下按钮时,它将通过给定的url方案调用第二个应用程序,反之亦然。

第一个应用看起来像...

struct ContentView: View {

    @State var message: String = ""

    var body: some View {

        Group {

            TextField("Enter message...", text: $message).textFieldStyle(.roundedBorder).padding()

            Button(action: {
                // go to second app

                let application = UIApplication.shared
                let secondAppPath = "second://\(self.message)"
                let appUrl = URL(string: secondAppPath)!

                application.open(appUrl, options: [ : ], completionHandler: nil)

                }) { Text("Go to second app")}
                .padding()
                .border(Color.black, width: 2)
        }
    }
}

和info.plist ...

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>second</string>
</array>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>first</string>
        </array>
    </dict>
</array>

第二个应用程序info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>first</string>
</array>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>second</string>
        </array>
    </dict>
</array>

当我在第一个应用程序中按下按钮时,第二个应用程序中的此功能应打印如下网址:“ second:// somethingfromthetextfield”

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    print(url)

    return true
}

但是它没有这样做。 第二个应用程序启动,但未打印任何内容。 现在我想知道,我做错了什么吗? 它是否可以在Xcode beta和SwiftUI上正常工作,还是工作方式不同?

尝试在SceneDelegate中使用以下方法:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    print("\(URLContexts.first!.url)")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM