で私は、コードを次しているのWebViewにviewcontroller.m負荷ローカルbasicmap.htmlファイルでできない負荷のGoogleマップローカルのhtmlファイル
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
// Create a map object and specify the DOM element for display.
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: false,
zoom: 8
});
console.log(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCvjeJZDdkpxCLasVMvTX2raxKkVGUULP8&callback=initMap"
async defer></script>
</body>
</html>
が含まれていbasicmap.htmlという名前のローカルのHTMLファイルを使用しています
#import "ViewController.h"
@interface ViewController()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"basicmap" withExtension:@"html"];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:_webView];
}
@end
出力には、webviewの空白ページが表示されます。 Info.plistファイルで
を使用し、私も NSAppTransportSecurityに \t \t \t NSAllowsArbitraryLoads Info.plistファイル –
使用中の \t \t \tこのメソッドを追加 - (ボイド)負荷HTMLString:(NSString *)string baseURL:(NSURL *)baseURL –
iOS
@Jigar 私はこれを使用します NSString * htmlFile = [[NSBundle mainBundle] pathForResource:@ "basic" ofType:@ "html" inDirectory:nil]; NSString * htmlString = [NSString stringWithContentsOfFile:htmlファイルのエンコード:NSUTF8StringEncodingエラー:nil]; [_webView loadHTMLString:htmlString baseURL:[[NSBundle mainBundle] bundleURL]]; これも動作しません/ –