我试图用 UIApplication 打开一个 URL,但是当我运行时:
[[UIApplication sharedApplication] canOpenURL:urlToUpdate
url 是用字符串创建的,
NSString *urlStringToOpenEscaped = [urlStringToOpen stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urlToUpdate = [NSURL URLWithString:urlStringToOpenEscaped];
总是返回 FALSE。
我检查了 URL 是否可以从 iPad 访问。
有什么想法吗?
最佳答案
canOpenURL
方法不用于测试网络 url 是否可达。根据文档:
This method guarantees that that if openURL: is called, another application will be launched to handle it. It does not guarantee that the full URL is valid.
因此,这是一种了解传递给方法的 url 指定的资源是否可以被系统上的应用程序访问/打开的方法。
如果您想检查一个网址是否可以访问,您必须执行请求,然后在响应中处理结果。
关于ios - canOpenURL 总是返回 FALSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13500098/