UIApplication -canOpenURL:-openURL:返回误导性结果 [英] UIApplication's -canOpenURL: -openURL: return misleading result

查看:488
本文介绍了UIApplication -canOpenURL:-openURL:返回误导性结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从iOS6开始,我无法判断应用程序是否可以启动Safari。

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

如果Safari在设备上受到限制(设置>常规>限制),尝试打开URL时没有任何反应,并且没有迹象表明出现了什么问题:

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

但是,Safari会启动,并且用户我想知道为什么我的按钮坏了。

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

这对我来说似乎是一个错误所以我提交了一个雷达#12449905。

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

还有另一种方法可以解决这个问题吗?

Is there another way to solve this problem?

推荐答案

如果这是Apple的bug,那么看起来喜欢你要做的就是围绕它编程。一旦用户单击该按钮,您总是可以这样写:

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];

在app delegate中,您可以设置如下属性:

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;
}

我确信有更好的方法,但至少你没有必须等待Apple。

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

这篇关于UIApplication -canOpenURL:-openURL:返回误导性结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆