From fa9651d1bb2d2852c1146498fc8b55be823f9031 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Sun, 4 Aug 2019 20:40:22 +0100 Subject: IOS7: Make sure openURL is executed on the main thread --- backends/platform/ios7/ios7_osys_misc.mm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/ios7/ios7_osys_misc.mm b/backends/platform/ios7/ios7_osys_misc.mm index d7743f8466..1f9232c12e 100644 --- a/backends/platform/ios7/ios7_osys_misc.mm +++ b/backends/platform/ios7/ios7_osys_misc.mm @@ -29,6 +29,14 @@ #include #include "common/translation.h" +static inline void execute_on_main_thread_async(void (^block)(void)) { + if ([NSThread currentThread] == [NSThread mainThread]) { + block(); + } else { + dispatch_async(dispatch_get_main_queue(), block); + } +} + Common::String OSystem_iOS7::getSystemLanguage() const { NSString *locale = [[NSLocale currentLocale] localeIdentifier]; if (locale == nil) @@ -79,11 +87,15 @@ bool OSystem_iOS7::openUrl(const Common::String &url) { // The way to oipen a URL has changed in iOS 10. Check if the iOS 10 method is recognized // and otherwise use the old method. if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) { - [application openURL:nsurl options:@{} completionHandler:nil]; - return true; + execute_on_main_thread_async(^ { + [application openURL:nsurl options:@{} completionHandler:nil]; + }); } else { - return [application openURL:nsurl]; + execute_on_main_thread_async(^ { + [application openURL:nsurl]; + }); } + return true; } bool OSystem_iOS7::isConnectionLimited() { -- cgit v1.2.3