1

If I open this url in Safari iOS would check if I have this app installed. If it is - the app will be launched otherwise I will be redirected to the AppStore app.

Is it possible to make UIWebView to do the same thing? The key thing is that system checks weather the app installed and has CFBundleURLTypes registered to respond.

EDIT: Sorry guys I was wrong with identifying the problem. There is actually another link that redirects to the direct (local) link that is registered for the app. I catch this now in

-(BOOL) webView:(UIWebView *)inWeb 
    shouldStartLoadWithRequest:(NSURLRequest *)inRequest 
    navigationType:(UIWebViewNavigationType)inType

and call

[[UIApplication sharedApplication] openURL:url]
Mark Parnell
  • 9,175
  • 9
  • 31
  • 36
Kostia Kim
  • 469
  • 1
  • 6
  • 19
  • You can always use `UIApplication openURL` to open this URL in Safari. I'm not sure if is it possible to do inside your app (without Safari), but note that Safari runs with different privileges (higher), so it might be impossible to do from inside a standard sandbox. – kuba Apr 06 '12 at 09:14

2 Answers2

3

If UIApplication openURL does what you want (open the app page in App Store or open the app if it's installed; I guess it will do so) you can "steal" the url opening event in the UIWebView in the following way:

// myWebView will be your initialized web view
[myWebView setDelegate:self];

// implement this method in the owning class
-(BOOL) webView:(UIWebView *)inWeb 
 shouldStartLoadWithRequest:(NSURLRequest *)inRequest 
             navigationType:(UIWebViewNavigationType)inType 
{
    if (inType == UIWebViewNavigationTypeLinkClicked) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }

    return YES;
}

This will open all links clicked in the web view in Safari / App Store / default handling app. If you want to open only iTunes links this way, you might want to implement some URL parsing in this method and redirect only those links. If you return YES, the default handler will be called i.e. the link will be opened in the web view.

MrTJ
  • 13,064
  • 4
  • 41
  • 63
1

The behavior you describe isn't how it currently works on iOS 5.1

clicking on iTMS link a second time will still launch App Store.

App Store on iOS 5.1


This may help you with detecting if a app already installed

https://stackoverflow.com/a/5746603/515359

Community
  • 1
  • 1
Denis Murphy
  • 1,137
  • 1
  • 11
  • 21