From 8c4ec71e26bf0ae4acdfcb3016adfa73f210c9da Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 19 Oct 2023 18:05:34 +0000 Subject: [PATCH] Retry the webkit load until we've connected to the server. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4542 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ios.m | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) 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