Last active
August 29, 2015 14:19
-
-
Save jolby/10973ad8cb18242a520c to your computer and use it in GitHub Desktop.
Creating JSContext for Ambly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
NSURL *jsCodeLocation; | |
// Loading JavaScript code - uncomment the one you want. | |
// OPTION 1 | |
// Load from development server. Start the server from the repository root: | |
// | |
// $ npm start | |
// | |
// To run on device, change `localhost` to the IP address of your computer, and make sure your computer and | |
// iOS device are on the same Wi-Fi network. | |
jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.101:8081/index.ios.bundle"]; | |
// OPTION 2 | |
// Load from pre-bundled file on disk. To re-generate the static bundle, run | |
// | |
// $ curl 'http://localhost:8081/index.ios.bundle?dev=false&minify=true' -o iOS/main.jsbundle | |
// | |
// and uncomment the next following line | |
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | |
// Set up the compiler output directory | |
NSURL* compilerOutputDirectory = [[self privateDocumentsDirectory] URLByAppendingPathComponent:@"cljs-out"]; | |
[self createDirectoriesUpTo:compilerOutputDirectory]; | |
NSLog(@"Using compile output dir: %@", compilerOutputDirectory); | |
// Set up our context | |
self.contextManager = [[ABYContextManager alloc] initWithContext:[[JSContext alloc] init] | |
compilerOutputDirectory:compilerOutputDirectory]; | |
[self.contextManager setUpAmblyImportScript]; | |
// Inject our context into the BTHContextExecutor (it sets the static variable) | |
[BTHContextExecutor setContext:self.contextManager.context]; | |
RCTBridge *bridge = [RCTBridge alloc]; | |
bridge.executorClass = [BTHContextExecutor class]; | |
[bridge initWithBundleURL:jsCodeLocation | |
moduleProvider:nil | |
launchOptions:launchOptions]; | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge | |
moduleName:@"AmblyApp"]; | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
UIViewController *rootViewController = [[UIViewController alloc] init]; | |
rootViewController.view = rootView; | |
self.window.rootViewController = rootViewController; | |
[self.window makeKeyAndVisible]; | |
// Now that React Native has been initialized, fire up our REPL server | |
self.replServer = [[ABYServer alloc] initWithContext:self.contextManager.context | |
compilerOutputDirectory:compilerOutputDirectory]; | |
BOOL successful = [self.replServer startListening]; | |
if (!successful) { | |
NSLog(@"Failed to start REPL server."); | |
} | |
NSLog(@"Launched App!"); | |
return YES; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment