简体   繁体   中英

URL Scheme iOS | Open Source Application Programmtically

I have 2 iOS applications, using URL Scheme I am able to open app B through A like I have created URL Scheme in B and using OpenURL calling it from application B . Also, I am able to pass the data.

But what I am looking for, is there a way to move back to application A on some specific event.

In B I am getting all details about A in sourceApplication but how to move back?

Do we need to create URL Scheme for both of the apps for communicating with each other? or is there any way to invoke sourceApplication and move back?

Issue 1

in case of Facebook SDK, I create URL Scheme for my app because once authentication is done I want Facebook SDK to call my app that right but I didn't register my app scheme in Facebook SDK info.plist. how does it work?

Issue 2 I have tried on Simulator and device both. if I call canOpenURL it gives me an error

-canOpenURL: failed for URL: "openb://" - error: "This app is not allowed to query for scheme openb"

But If I directly call UIApplication.shared.open it launches the application successfully.

Any leads here?

If you want to invoke iOS application from another iOS app URL Scheme is the way. A URL scheme lets you communicate with other apps through a protocol that you define. To communicate with an app that implements such a scheme, you must create an appropriately formatted URL and ask the system to open it. To implement support for a custom scheme, you must declare support for the scheme and handle incoming URLs that use the scheme.

How to move back or open sourceApplication?

To achieve this you have to create URL Scheme for both of the application.

Issue 1 and 2

Before iOS 8, everyone was using canOpenURL for checking whether this URL is exist for not and if yes openURL for invoking the application. But concern came when few developers/apps started using it to track the user iPhone (what all application is installed) for advertising purposes etc. That's why Apple came up with the solution called URL Scheme Whitelist .

So according to that, if you want to use canOpenURL you have to whitelist the URL Scheme otherwise it will through an error like error: This app is not allowed to query for scheme and if you want to open the application use openURL directly.

Yes it broke lots of SDKs login flow but it makes sense.

For more information, canOpenURL(_:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM