use*_*331 0 objective-c uiwebview ios
我想让UIWebView暂时显示google.com,但它没有加载:
我只是得到一个空白的屏幕
.H
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end
Run Code Online (Sandbox Code Playgroud)
.M
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *targetURL = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[_webView loadRequest:request];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Run Code Online (Sandbox Code Playgroud)
我做的是创建Web视图的以下内容:
我尝试添加以下内容:
[self.view addSubview:self.webView];
Run Code Online (Sandbox Code Playgroud)
那什么都没做
如果您在iOS> 9.0上运行Web View,可能您尚未将NSAppTransportSecurity密钥添加到项目*.plist文件中,因此应用程序无法请求任何URL.
如果要允许所有URL请求,则应将以下代码添加到项目plist文件中:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
否则,如果您只想允许特定的URL请求:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>allowed.domain.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9475 次 |
| 最近记录: |