Xcode 7 UIWebView不加载url

我在我的应用程序中使用UIWebView,它在Xcode4,5,6模拟器中一切正常。 但不是为Xcode 7模拟器,我不知道为什么,模拟器中没有警告或错误,而屏幕只是显示空白页面。 请帮帮我。 谢谢。

#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. } 

Xcode 7与iOS9现在迫使你不使用HTTP调用,但HTTPS的。

这是AppTransportSecurity中增强的安全性点。

尝试这个:

  • 去你的info.plist
  • 添加一个名为NSAppTransportSecurity的字典
  • 添加一个布尔属性到这个名为NSAllowsArbitraryLoads
  • 将其传递给TRUE

重新加载您的应用程序。

我build议你,如果苹果想阻止HTTP(不安全)的电话是有原因的。 http://www.originoftime.net/index-cn有一个HTTPS,但服务器证书似乎是自签名的。

让我知道这个解决方法是否适合你

来自法国的欢呼声

你是否实现了Web视图委托方法? 尤其是:

 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 

如果加载失败,那会告诉你什么是问题。

这很可能是与正在为networking访问实施的新安全模型相关的错误。 您可以通过将以下内容添加到Info.plist文件中来覆盖此新行为。 只需编辑XML并将其粘贴到:

 <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict> 

这些更改总结在这里: https : //developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html