AppClip 如何从 URL 中获取查询项

AppClip how to get query items from the URL

当 AppClips 打开时,我想从 link => https://example.com/token=12ds234vssd

中读取令牌的值

这是 SwiftUI 示例:

var body: some Scene
{
    WindowGroup
    {
        ContentView().onContinueUserActivity(NSUserActivityTypeBrowsingWeb, perform: handleUserActivity)
    }
}

func handleUserActivity(_ userActivity: NSUserActivity)
{
    guard let incomingURL = userActivity.webpageURL,
          let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true),
          let queryItems = components.queryItems else
    {
        return
    }
    // Configure App Clip with query items
    print(String(queryItems))         
}

如何使用 UIKit 编写代码?

我可以在 UIKit 上编写相同的语法吗?

场景代表:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    for activity in connectionOptions.userActivities where activity.activityType == NSUserActivityTypeBrowsingWeb {
        appClipCodeURL = activity.webpageURL
        print("appClipCodeURL: ",appClipCodeURL)
    }  
}