Skip to content

Instantly share code, notes, and snippets.

@blairio
Created April 13, 2016 15:24
Show Gist options
  • Save blairio/ea8570f7db4311818692594473c185ca to your computer and use it in GitHub Desktop.
Save blairio/ea8570f7db4311818692594473c185ca to your computer and use it in GitHub Desktop.
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "AppDelegate.h"
#import "RCTRootView.h"
#import "CouchbaseLite/CouchbaseLite.h"
#import "CouchbaseLiteListener/CBLListener.h"
#import "CBLRegisterJSViewCompiler.h"
@interface AppDelegate()
@property (strong, nonatomic) CBLManager *cbManager;
@property (strong, nonatomic) CBLListener *cbListener;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"applicationDidFinishLaunchingWithOptions");
NSURL *jsCodeLocation;
if (RCT_DEV) {
/**
* 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
* (you can get this by typing `ifconfig` into the terminal and selecting the
* `inet` value under `en0:`) and make sure your computer and iOS device are
* on the same Wi-Fi network.
*/
#if TARGET_IPHONE_SIMULATOR
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
#else
// jsCodeLocation = [NSURL URLWithString:@"http://computer.local:8081/index.ios.bundle?platform=ios&dev=true"];
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
} else {
/**
* OPTION 2
* Load from pre-bundled file on disk. The static bundle is automatically
* generated by "Bundle React Native code and images" build step.
*/
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
}
[self launchCouchbaseLite];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"TestPaymentCollector"
initialProperties:nil
launchOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"applicationDidEnterBackground");
[self.cbListener stop];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"applicationWillEnterForeground");
NSError *anyError;
if (![self.cbListener start:&anyError]) {
NSLog(@"applicationWillEnterForeground: cbListener start failed with error: %@", anyError);
};
}
- (void)launchCouchbaseLite
{
NSLog(@"Launching Couchbase Lite...");
_cbManager = [CBLManager sharedInstance];
CBLRegisterJSViewCompiler();
_cbListener = [[CBLListener alloc] initWithManager:_cbManager port:5984];
[_cbListener start:nil];
NSLog(@"Couchbase Lite url = %@, and port %d", _cbManager.internalURL, _cbListener.port);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment