Xcode 7 UIWebView不会加载网址 [英] Xcode 7 UIWebView doesn't load url
问题描述
我在我的应用程序中使用UIWebView,并且在Xcode4、5、6模拟器中一切正常.但不是针对Xcode 7模拟器的,我不知道为什么,模拟器中没有警告或错误,并且屏幕仅显示空白页.请帮我.谢谢.
I use UIWebView in my app and it all worked fine in Xcode4,5,6 simulator. but not for Xcode 7 simulator, I don't know why, there is no warning or error in simulator, and the screen is just showing blank page. Please help me. Thanks.
#import "IndexViewController.h"
@interface IndexViewController ()
@end
@implementation IndexViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlString = nil;
NSString *languageCode = [[NSLocale preferredLanguages] objectAtIndex:0];
if ([languageCode isEqualToString:@"zh-Hans"]) {
urlString = @"http://www.originoftime.net/index-cn";
}else if ([languageCode isEqualToString:@"zh-Hant"]) {
urlString = @"http://www.originoftime.net/index-cn";
}else{
urlString = @"http://www.originoftime.net/index-en";
}
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
[_Index loadRequest:urlrequest];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
推荐答案
带有iOS9的Xcode 7现在会强制您不要使用HTTP调用,而是使用HTTPS调用.
Xcode 7 with iOS9 now force you to not use HTTP call, but HTTPS ones.
这是AppTransportSecurity中增强的安全点.
this is a security point enhanced in AppTransportSecurity.
尝试一下:
- 转到您的info.plist
- 添加一个名为NSAppTransportSecurity的字典
- 向此属性添加一个布尔属性,称为NSAllowsArbitraryLoads
- 将其传递为TRUE
重新加载您的应用.
我建议您,如果Apple要阻止HTTP(不安全的)调用是有充分理由的. http://www.originoftime.net/index-cn 具有HTTPS,但服务器证书似乎是自发的.签名.
I advice you that if Apple want to block HTTP (unsecured) calls is for a good reason. http://www.originoftime.net/index-cn has a HTTPS one but the server certificate seems to be self-signed.
让我知道此替代方法是否对您有用
Let me know if this workaround work for you
来自法国的欢呼声
这篇关于Xcode 7 UIWebView不会加载网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!