diff --git a/AppWithModules/Source Files/main.m b/AppWithModules/Source Files/main.m index 4e806143..dacca262 100644 --- a/AppWithModules/Source Files/main.m +++ b/AppWithModules/Source Files/main.m @@ -24,7 +24,8 @@ int main(int argc, char *argv[]) { config.ArgumentsCount = argc; config.Arguments = argv; - nativescript = [NativeScript alloc] initWithConfig: config]; + nativescript = [[NativeScript alloc] initWithConfig: config]; + [nativescript runMainApplication]; return 0; } diff --git a/NativeScript/NativeScript.h b/NativeScript/NativeScript.h index 8de8b7af..a8912188 100644 --- a/NativeScript/NativeScript.h +++ b/NativeScript/NativeScript.h @@ -15,6 +15,10 @@ @interface NativeScript : NSObject - (instancetype)initWithConfig:(Config*)config; +/** + WARNING: this method does not return in most applications. (UIApplicationMain) + */ +- (void)runMainApplication; - (bool)liveSync; @end diff --git a/NativeScript/NativeScript.mm b/NativeScript/NativeScript.mm index c28cdd04..806b521f 100644 --- a/NativeScript/NativeScript.mm +++ b/NativeScript/NativeScript.mm @@ -53,18 +53,20 @@ - (instancetype)initWithConfig:(Config*)config { inspectorClient->registerModules(); inspectorClient->connect([config ArgumentsCount], [config Arguments]); } - - runtime_->RunMainScript(); - - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); - - tns::Tasks::Drain(); } return self; } +- (void)runMainApplication { + runtime_->RunMainScript(); + + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); + + tns::Tasks::Drain(); +} + - (bool)liveSync { if (runtime_ == nullptr) { return false; diff --git a/TestRunner/Source Files/main.m b/TestRunner/Source Files/main.m index 09132690..a1330c51 100644 --- a/TestRunner/Source Files/main.m +++ b/TestRunner/Source Files/main.m @@ -25,6 +25,7 @@ int main(int argc, char *argv[]) { config.Arguments = argv; nativescript = [[NativeScript alloc] initWithConfig:config]; + [nativescript runMainApplication]; return 0; } diff --git a/project-template/internal/main.m b/project-template/internal/main.m index 43ffeef1..03767c84 100644 --- a/project-template/internal/main.m +++ b/project-template/internal/main.m @@ -57,6 +57,7 @@ int main(int argc, char *argv[]) { config.Arguments = argv; nativescript = [[NativeScript alloc] initWithConfig:config]; + [nativescript runMainApplication]; return 0; }