NSAppTransportSecurity UIWebView 问题
NSAppTransportSecurity UIWebView issue
我的 info.plist 文件中有这些行:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>mysebserver.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
所以它非常适合我的 API 电话。
在我的视图控制器中,我有 UIWebView 试图显示网页内容:
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.webSiteUrlSting] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[self.theWebView loadRequest:request];
在 iOS7 和 iOS8 上效果很好,但在 iOS9 上它在调用 UIWebView 委托后显示错误 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
:
App Transport Security has blocked a cleartext HTTP (http://) resource
load since it is insecure. Temporary exceptions can be configured via
your app's Info.plist file.
委托方法包含如下所示的错误实例:
Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be
loaded because the App Transport Security policy requires the use of a
secure connection." UserInfo={NSUnderlyingError=0x7fbaa253ba20 {Error
Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be
loaded because the App Transport Security policy requires the use of a
secure connection."
UserInfo={NSErrorFailingURLStringKey=requestedwebsite.com,
NSLocalizedDescription=The resource could not be loaded because the
App Transport Security policy requires the use of a secure
connection.,
NSErrorFailingURLKey=requestedwebsite.com}},
NSErrorFailingURLStringKey=requestedwebsite.com,
NSErrorFailingURLKey=requestedwebsite.com,
NSLocalizedDescription=The resource could not be loaded because the
App Transport Security policy requires the use of a secure
connection.}
我的问题是如何使我的 API 请求正常工作并使 UIWebView 正常工作。
在您的 NSAppTransportSecurity
字典中添加此例外:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
我的 info.plist 文件中有这些行:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>mysebserver.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
所以它非常适合我的 API 电话。
在我的视图控制器中,我有 UIWebView 试图显示网页内容:
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.webSiteUrlSting] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[self.theWebView loadRequest:request];
在 iOS7 和 iOS8 上效果很好,但在 iOS9 上它在调用 UIWebView 委托后显示错误 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
委托方法包含如下所示的错误实例:
Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x7fbaa253ba20 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=requestedwebsite.com, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLKey=requestedwebsite.com}}, NSErrorFailingURLStringKey=requestedwebsite.com, NSErrorFailingURLKey=requestedwebsite.com, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}
我的问题是如何使我的 API 请求正常工作并使 UIWebView 正常工作。
在您的 NSAppTransportSecurity
字典中添加此例外:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>