我一直在关注此链接以使用x-callback-url
. 所以我制作了两个不同的应用程序 - SourceApp和TargetApp。
源应用
并实现打开 TargetApp 如下:
@IBAction func btnOpenAppPressed(_ sender:UIButton){
let url = URL.init(string: "targetapp://x-callback-url/translate?x-success=sourceapp://x-callback-url/acceptTranslation&x-source=SourceApp&x-error=sourceapp://x-callback-url/translationError&word=Hello&language=Spanish")
if (UIApplication.shared.canOpenURL(url!)){
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
}
}
AppDelegate 方法从 TargetApp 接收响应:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("Response From TargetApp==>\(url.absoluteString)")
return true
}
目标应用
AppDelegate 方法接收来自 SourceApp 的请求:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("Response From SourceApp==>\(url.absoluteString)")
return true
}
TargetApp 的 IBAction 将响应发送回 SourceApp:
@IBAction func btnBackToSourceAppPressed(_ sender:UIButton){
let url = URL.init(string: "sourceapp://x-callback-url/acceptTranslation?x-source=TargetApp&word=Hola")
if (UIApplication.shared.canOpenURL(url!)){
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
}
}
现在的问题是,我可以从 SourceApp 打开 TargetApp,但无法从 TargetApp 返回到 SourceApp。我什至研究过这种方法,但我发现它和我的一样。
任何帮助将不胜感激。