How can I launch back the app that opened my custom URL scheme?

*爱你&永不变心* 提交于 2019-12-01 03:54:08

问题


I'm working on an app that manages my own URL scheme so I implement the callback:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions
{
    // Get our launch URL
    if (launchOptions != nil)
    {
        // Launch dictionary has data
        NSURL* launchURL = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey];

        // Parse the URL
        NSString* hostString = [launchURL host];

        blah blah blah...

It works very nice but I need to launch the caller application (i.e. the app that opened the URL). So my question here is, is it possible?

I have been playing with UIApplicationLaunchOptionsSourceApplicationKey but I can't launch back the app by its application Bundle ID. Can I?

I have also tried the undocumented launchApplicationWithIdentifier: of UIApplication, but I need a real solution and it seems that workaround only works in the Simulator.

Any ideas? Thank you!


回答1:


The only way would be to have both apps each support a custom URL scheme. Then you embed the caller URL in the URL of the other app.

For example, let's say App2 wants to call App1 in a way so that App1 could then "call back" to App2. It would create and open an URL like this:

app1://?caller=app2%3A%2F%2Fblabla

When you decode the caller part you would get back the string app2://blabla which you could then again open with openURL: to "call back".



来源:https://stackoverflow.com/questions/9022967/how-can-i-launch-back-the-app-that-opened-my-custom-url-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!