我在我的应用程序中使用方案将数据从第二个应用程序传递到我的应用程序。 我已经可以使用第二个应用程序的方案打开我的应用程序。 但现在我想解析从第二个应用程序发送的 URL 数据。我在网上找到了一个关于在我的 viewController 类中实现如下所示方法的教程,但该方法从未被触发。我需要把它放在特定的地方吗?现在它就在 viewController 类中。
这周我刚刚开始用 Swift 编码来创建 POC,我有更多的 Android 背景。
func application(app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool {
// Determine who sent the URL.
let sendingAppID = options[.sourceApplication]
print("source application = \(sendingAppID ?? "Unknown")")
// Process the URL.
guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
// let ro_response = components.path,
let params = components.queryItems else {
print("Invalid")
return false
}
if let serial = params.first(where: { $0.name == "serial" })?.value {
self.SERIAL = serial as String
} else {
return false;
}
if let otp = params.first(where: { $0.name == "otp" })?.value {
self.OTP = otp as String
} else {
return false;
}
return true
}
最佳答案
这是来自 UIApplicationDelegate
的方法,因此您必须在 AppDelegate
中实现它。
关于swift - 从其他应用程序接收方案数据的功能未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58353611/