Comming back to the app after launching safari

Discussion in 'iPhone/iPad Programming' started by cyberserker, Apr 23, 2009.

  1. macrumors newbie

    Joined:
    Apr 17, 2009
    Messages:
    6
    Location:
    France (Lyon)
    #1
    I put some links in my app that launch safari when asked:

    Code:
    - (IBAction)jumpToUrl:(id)sender {
    	UIButton *url = (UIButton *)sender;
    	NSString *urlString = [NSString stringWithFormat:@"http://%@", url.currentTitle];
    	if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]])
    	{
    		// there was an error trying to open the URL. for the moment we'll simply ignore it.
    	}
    }
    
    Unfortunately, the backbutton in safari is inactive with no means to the user to go back to the app.

    Any idea?
     
  2. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #2
    The back button is not meant to take the user back to your app: it's for browsing backwards in the browser history. If the user wants to come back to your app they hit the home button and launch your app again. Just like any other app.
     
  3. macrumors newbie

    Joined:
    Apr 17, 2009
    Messages:
    6
    Location:
    France (Lyon)
    #3
    In fact, it is possible using the Google App!!!

    I tried it yesterday and it works well, giving the user the opportunity to go back and forth between safari and Google App.
     
  4. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #4
    Well then I'd suggest asking Google how they do it as there is no direct support for it in the SDK. The only way I can see of doing it is to register a URI scheme for you app and somehow arrange for this to be added to the browser history stack in the correct place (via javascript possibly).
     
  5. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #5
    I've just installed the Google app. They appear to do this by directing you to a special site first (at a specific IP address, no doubt on they control) which then redirects you to the site you wanted. When you hit back you go to that site and it then re-launches the Google app (via a registered URL handler on the phone).

    So there you go: if you want to do this you now know how.
     

Share This Page