16

Since iOS6, I can't tell whether the application can launch Safari or not.

If Safari is restricted on the device (Settings>General>Restrictions), nothing happens when trying to open a URL, and there's no indication of what went wrong:

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
[[UIApplication sharedApplication] canOpenURL:url]; // Returns YES
[[UIApplication sharedApplication] openURL:url]; // Returns YES

However, Safari does not launch, and the user is left wondering why my buttons are "broken".

This seems like a bug to me so I filed a radar #12449905.

Is there another way to solve this problem?

hwaxxer
  • 3,363
  • 1
  • 22
  • 39
  • Are radars public? I can't find any "search" button beside that one for searching radars I submitted myself… – jcayzac Oct 11 '12 at 02:17
  • @jcayzac No, but I added it to openradar: http://openradar.appspot.com/12449905 – hwaxxer Oct 11 '12 at 09:37
  • Does it work with `https://`? Since it's a bug, it might just randomly decide to work with a different URL scheme for no apparent reason. – Greg Oct 15 '12 at 05:21
  • Maybe sending the URL to a UIWebView within your app may be a workaround. – CuriousRabbit Oct 18 '12 at 03:10
  • @PartiallyFinite `https` does not help. @CuriousRabbit may work for some but still doesn't solve the problem. – hwaxxer Oct 18 '12 at 08:15
  • @hwaxxer did you also create a bugreport for apple? – Bot Oct 25 '12 at 16:29
  • I've run into this same problem and can confirm it's a bug (the method doesn't return the expected result). In my case I cannot program around it like described below. I'm using this test to determine if Safari is disabled in parental controls, and if so, I disable my own integrated web browser as a curtesy to users. At least that's what I want to do. – Michael Nov 01 '12 at 17:46

1 Answers1

2

If this is an Apple bug, then it looks like the thing for you to do is to program around it. Once the user clicks the button, you can always write something like this:

[self performSelector:@selector(notifyUserOfRestrictedAccess) withObject:self afterDelay:.5];

In the app delegate, you can set a property such as:

- (void)applicationWillResignActive:(UIApplication *)application {
    self.openingExternalProgram = YES;
}

In your view controller, create the method like this:

-(void) notifyUserOfRestrictedAccess {

    if (!appDelegate.openingExternalProgram) {
        // Message the user via UIAlertView about restricted Safari access
    }
    appDelegate.openingExternalProgram = NO;
}

I'm sure there are better ways, but at least you don't have to wait on Apple.