I have been following this link to implement interapp two way communication using x-callback-url
. So I made two different app - SourceApp & TargetApp.
SourceApp
And implementation to open TargetApp as follows:
@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 method to receive the response back from TargetApp:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("Response From TargetApp==>\(url.absoluteString)")
return true
}
TargetApp
AppDelegate method to receive the request from SourceApp:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("Response From SourceApp==>\(url.absoluteString)")
return true
}
IBAction of TargetApp to send the response back to 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)
}
}
Now the problem is, I can open the TargetApp from SourceApp but can't return from TargetApp to SourceApp. I even looked into this approach but I found it same as mine.
Any help will be appreciated.