Xcode 7 UIWebView 未加载 url

Xcode 7 UIWebView doesn't load 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 with iOS9 现在强制您不使用 HTTP 调用,而是使用 HTTPS 调用。

这是 AppTransportSecurity 中增强的安全点。

试试这个:

  • 转到您的 info.plist
  • 添加名为 NSAppTransportSecurity 的字典
  • 给这个添加一个布尔属性,叫做 NSAllowsArbitraryLoads
  • 将其传递给 TRUE

重新加载您的应用程序。

我建议您,如果 Apple 想要阻止 HTTP(不安全)调用是有充分理由的。 http://www.originoftime.net/index-cn 有一个 HTTPS 证书,但服务器证书似乎是自签名的。

让我知道此解决方法是否适合您

来自法国的欢呼

您是否实现了 Web 视图委托方法?特别是:

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

如果加载失败,它会告诉您问题所在。

这很可能是与网络访问强制执行的新安全模型相关的错误。您可以通过将以下内容添加到 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