diff --git a/src/ios.m b/src/ios.m index 77cdc152..1d2545b2 100644 --- a/src/ios.m +++ b/src/ios.m @@ -1,6 +1,5 @@ -#include "log.h" - #import +#import #import #import #import @@ -10,10 +9,16 @@ void tf_run_thread_start(const char* zip_path); -@interface ViewController : UIViewController +@interface ViewController : UIViewController @property(strong, nonatomic) WKWebView* web_view; +@property bool initial_load_complete; @end +static void _start_initial_load(WKWebView* web_view) +{ + [web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]]; +} + @implementation ViewController : UIViewController - (void)viewDidLoad { @@ -21,8 +26,22 @@ void tf_run_thread_start(const char* zip_path); WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init]; self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration]; self.web_view.UIDelegate = self; - [self.web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]]; + self.web_view.navigationDelegate = self; [self.view addSubview:self.web_view]; + _start_initial_load(self.web_view); +} + +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation +{ + self.initial_load_complete = true; +} + +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error +{ + if (!self.initial_load_complete) + { + _start_initial_load(self.web_view); + } } - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler