From 2da2fad26c9dcf38832a170ce0e019f8a6ae1a19 Mon Sep 17 00:00:00 2001 From: Donald Date: Tue, 11 Sep 2018 09:32:02 +0800 Subject: [PATCH] Fix Runtime Issues: ScratchJr.m: runtime: UI API called from background thread: -[UIView removeFromSuperview] must be used from main thread only IO.m: runtime: UI API called from background thread: -[UIWebView stringByEvaluatingJavaScriptFromString:] must be used from main thread only --- ios/ScratchJr/src/IO.m | 12 +++++++----- ios/ScratchJr/src/ScratchJr.m | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ios/ScratchJr/src/IO.m b/ios/ScratchJr/src/IO.m index 1d11d86..f2eea80 100644 --- a/ios/ScratchJr/src/IO.m +++ b/ios/ScratchJr/src/IO.m @@ -280,12 +280,14 @@ NSMutableDictionary *soundtimers; } + (void)soundEnded:(NSTimer*)timer { - NSString *soundName = [[timer userInfo] objectForKey:@"soundName"]; - if (sounds[soundName] == nil) return; - NSString *callback = [NSString stringWithFormat:@"iOS.soundDone('%@');", soundName]; - UIWebView *webview = [ViewController webview]; + NSString *soundName = [[timer userInfo] objectForKey:@"soundName"]; + if (sounds[soundName] == nil) return; + NSString *callback = [NSString stringWithFormat:@"iOS.soundDone('%@');", soundName]; + UIWebView *webview = [ViewController webview]; + dispatch_async(dispatch_get_main_queue(), ^{ [webview stringByEvaluatingJavaScriptFromString:callback]; - } + }); +} + (NSString *)stopSound :(NSString*)name { AVAudioPlayer *snd = sounds[name]; diff --git a/ios/ScratchJr/src/ScratchJr.m b/ios/ScratchJr/src/ScratchJr.m index 7d531f8..e5b6cca 100644 --- a/ios/ScratchJr/src/ScratchJr.m +++ b/ios/ScratchJr/src/ScratchJr.m @@ -19,7 +19,9 @@ NSString *oncomplete; + (NSString *) hideSplash :(NSString *)body{ UIImageView* splashScreen = [ViewController splashScreen]; - [splashScreen removeFromSuperview]; + dispatch_async(dispatch_get_main_queue(), ^{ + [splashScreen removeFromSuperview]; + }); return @"1"; }