5

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!

Costique
  • 23,712
  • 4
  • 76
  • 79
zapador
  • 897
  • 2
  • 11
  • 20
  • I'm trying to do a very similar thing, after opening my app from Safari I want to switch back to Safari (without loading a new URL). I want to simply open Safari as if I switched to it using the Task Switcher. Please can you elaborate on the "undocumented method" you have used to achieve this? – Plasma Sep 05 '12 at 21:18
  • One workaround on iPad is to make the user aware of built-in gesture: *Four-finger horizontal swipe across the screen to return to previous app*. Seems to be iPad-only, not on handheld devices. – Basil Bourque May 06 '13 at 20:51

1 Answers1

2

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".

DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • Yes, I'm afraid it's impossible without each app supporting custom URL scheme. Just want to exhaust all possibilities, thanks DarkDust! – zapador Jan 26 '12 at 18:28
  • 1
    There should be some other way.. have you seen facebook app... we go to facebook app for authentication and then facebook app open our app.. even when our app dont have custom url scheme.. – Saurabh Jan 26 '12 at 18:30
  • 2
    That's because the apps authenticating with facebook SSO(single sign on) register their custom URL scheme with facebook. – Lance Jan 26 '12 at 18:32
  • Yes, Facebook SSO needs that the client app register a URL scheme based on the "Facebook App Id". Back to the mentioned `UIApplicationLaunchOptionsSourceApplicationKey`, what is it for? Is it just for distinguish the launcher apps? – zapador Jan 27 '12 at 15:13
  • 1
    @zapador using my imagination: it'd be useful to behave differently depending on what app launched my app, for example by launching that other app if I know it supports a particular custom URL scheme – aehlke Dec 30 '15 at 04:07