描述:
我正在使用 SwiftUI 开发 iOS App Clip,但遇到了单击通用链接时 App Clip 无法启动的问题。以下是我的设置和我尝试过的关键细节:
主应用程序上下文:主应用程序是使用 Flutter 构建的,但 App Clip 是在 SwiftUI 中原生开发的。
当前目标:我的目标是演示单击通用链接时 App Clip 的启动。目前,它不需要与主应用程序交互或处理任何参数 - 目标只是让它启动。
开发环境:我正在通过 Xcode 构建 App Clip,并通过运行 App Clip 然后单击链接来测试它。
配置:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "<TeamId>.<BundleId of main app>",
"paths": ["/redeem"]
}
]
},
"appclips": {
"apps": ["<TeamId>.<BundleId of app clip>"]
}
}
import SwiftUI
import FirebaseCore
import FirebaseAuth
@main
struct AppName_ClipApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL(perform: { url in
print("Opened URL: \(url)")
})
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func
application(_
application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("Your code here")
return true
}
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL {
print("Opened URL from Universal Link: \(url)")
// Handle the URL appropriately within your app
}
return true
}
}
我正在寻求有关我的设置中是否缺少某些内容或者我的实施是否存在任何问题的指导。任何关于为什么 App Clip 不通过通用链接启动的建议或见解将不胜感激。
也许 onOpenUrl 在 App Clip 上不起作用。 你必须使用 onContinueUserActivity 方法。