Anche se non ho una risposta rapida (intendo una soluzione rapida) ho una soluzione.
Si tratta di rinunciare al file: // protocollo e passare a http: // su localhost.
BREVE RISPOSTA
Ecco i passaggi:
1) - Installare un server Web locale nel proprio app;
2) - Impostare il server Web locale per servire da localhost su una determinata porta di propria scelta;
3) - Impostare il delegato che effettivamente serve il file dalle risorse dell'app dato il giusto tipo di mime;
4) - Autorizza a bypassare iOS9 ATS per gestire http (e non solo https).
E voilà!
DETTAGLIATA RISPOSTA
1) Installare un server Web locale nel proprio app;
Installare il GCDWebServer fro suo repo GitHub: https://github.com/swisspol/GCDWebServer
2) Configurazione del server Web locale per servire da localhost ad una data porta del
Dato tuoi angularjs o file app HTML si trovano nella cartella "app" nella cartella delle risorse.
Nel vostro vc viewDidLoad:
@implementation ViewController
GCDWebServer* _webServer;
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView = [[WKWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:self.webView];
self.webView.navigationDelegate = self;
NSURL *bundleURL = [NSBundle mainBundle].bundleURL;
NSURL *basePath = nil;
// Init WebServer
[self initWebServer:[[NSURL URLWithString:@"app" relativeToURL:bundleURL] absoluteURL]];
basePath = [NSURL URLWithString:@"http://localhost:8080/page.html#/home" relativeToURL:nil];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:basePath];
[self.webView loadRequest:request];
}
3) Impostare il delegato che in realtà servono il file dalla tua applicazione ressources dato il tipo MIME destra;
-(void)initWebServer:(NSURL *)basePath {
// Create server
_webServer = [[GCDWebServer alloc] init];
#define GCDWebServer_DEBUG 0
#define GCDWebServer_VERBOSE 1
#define GCDWebServer_INFO 2
#define GCDWebServer_WARNING 3
#define GCDWebServer_ERROR 4
#define GCDWebServer_EXCEPTION 5
[GCDWebServer setLogLevel:GCDWebServer_ERROR];
// Add a handler to respond to GET requests on any URL
[_webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
//NSLog([NSString stringWithFormat:@"WS: loading %@", request]);
NSString * page = request.URL.lastPathComponent;
NSString * path = request.URL.path;
NSString * file = path;
//NSLog(@"WS: loading %@", file);
NSString * fullPath = [NSString stringWithFormat:@"%@%@", basePath, path];
NSString * sFullPath = [fullPath substringFromIndex:7];
BOOL isText = NO;
if([page.lastPathComponent hasSuffix:@"html"]) {
isText = YES;
}
if (isText) {
NSError * error = nil;
NSString * html = [NSString stringWithContentsOfFile:sFullPath encoding:NSUTF8StringEncoding error: &error];
return [GCDWebServerDataResponse responseWithHTML:html];
}
else {
NSData * data = [NSData dataWithContentsOfFile:sFullPath];
if (data !=nil) {
NSString * type = @"image/jpeg";
if ([page.lastPathComponent hasSuffix:@"jpg"]) type = @"image/jpeg";
else if ([page.lastPathComponent hasSuffix:@"png"]) type = @"image/png";
else if ([page.lastPathComponent hasSuffix:@"css"]) type = @"text/css";
else if ([page.lastPathComponent hasSuffix:@"js" ]) type = @"text/javascript";
return [GCDWebServerDataResponse responseWithData:data contentType:type];
}
else {
return [GCDWebServerDataResponse responseWithHTML:[NSString stringWithFormat:@"<html><body><p>404 : unknown file %@ World</p></body></html>", sFullPath]];
//return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"];
}
}
}];
// Start server on port 8080
[_webServer startWithPort:8080 bonjourName:nil];
NSLog(@"Visiting %@", _webServer.serverURL);
}
4) Autorizzazione per bypassare iOS9 ATS per gestire http (https e non solo)
Nel file info.plist in Xcode, è necessario aggiungere un dizionario di nome "Impostazioni App Transport Security "con al suo interno un valore-chiave come segue:
NSAllowsArbitraryLoads = true
Speranza che aiuta. Chiunque imbattersi in qualcosa di più semplice è il benvenuto a rispondere!
Sai che puoi connettere Safari Web Inspector a WKWebView per vedere gli errori nella console? Questo potrebbe fornire ulteriori suggerimenti. –
@stefan arentz certo. Ho migliorato la descrizione del mio problema con schermate. –
@stefan arentz Grande funzionalità! – AppsolutEinfach