UIApplication's -canOpenURL: -openURL: return misleading result

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 07:09:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12771177/uiapplications-canopenurl-openurl-return-misleading-result

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