我创建了一个带有扫描按钮的键盘扩展,用于在我包含的应用程序中打开条形码扫描仪。扫描完成后,它应该导航回初始应用程序,条形码数据应设置为启动键盘的文本字段的文本,然后我们单击扫描按钮。
这个应用程序 Scandit Wedge 以同样的方式执行此操作。但我找不到实现相同目标的方法。 请引用下面的 GIF。
https://s3.amazonaws.com/id123-dev-ios/scandit.gif
如有任何帮助,我们将不胜感激。
最佳答案
没有公共(public)API可以切换到以前的应用程序,这里是答案:https://stackoverflow.com/a/13447282/1433612
但如果您知道应用程序的包 ID 和 url 方案,则可以这样做。您可以在互联网上找到非官方列表。假设您能够识别源应用程序,您可以在 AppDelegate
中执行类似的操作:
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
guard let applicationBundleId = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String else {
return true
}
// Save your source application
sourceApplicationBundleId = applicationBundleId
return true
}
var sourceApplicationBundleId: String?
// Attempt to open application from which your app was opened
func openApplication() {
guard let applicationBundleId = sourceApplicationBundleId, let url = url(for: applicationBundleId) else {
return
}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
func url(for bundleId: String) -> URL? {
guard let scheme = knownUrlSchemes[bundleId] else {
return nil
}
return URL(string: scheme)!
}
// A list of known url schemes
var knownUrlSchemes: Dictionary<String, String> = {
return ["com.google.Maps": "comgooglemaps://",
"com.facebook.Facebook": "fb://"]
}()
关于ios - 在深层链接的情况下,以编程方式包含应用程序的反向链接到以前的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47216328/