Last active
November 18, 2015 07:12
-
-
Save jsierles/53fd0514d6f48e0c5872 to your computer and use it in GitHub Desktop.
React Native App Reloader
This file contains hidden or 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
#import "AppDelegate.h" | |
#import "ViewController.h" | |
@interface AppDelegate() | |
@property (nonatomic, strong) ViewController *viewController; | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
NSURL *initialJSBundleURL; | |
NSString *initialModuleName; | |
initialJSBundleURL = [NSURL URLWithString:[[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"] absoluteString]]; | |
initialModuleName = @"MyAppModule"; | |
self.viewController = [[ViewController alloc] initWithLaunchOptions:launchOptions]; | |
[self.viewController reloadWithJSBundleURL:initialJSBundleURL moduleNamed:initialModuleName]; | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
self.window.rootViewController = self.viewController; | |
self.window.backgroundColor = [UIColor blackColor]; | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} | |
@end | |
#import "RCTBridgeModule.h" | |
@interface AppReloader : NSObject <RCTBridgeModule> | |
@end | |
@implementation AppReloader | |
RCT_EXPORT_MODULE() | |
-(dispatch_queue_t)methodQueue | |
{ | |
return dispatch_get_main_queue(); | |
} | |
/** | |
* var AppReloader = require('NativeModules').AppReloader; | |
* AppReloader.reloadAppWithURLString('https://example.com/index.ios.bundle', 'App') | |
*/ | |
RCT_EXPORT_METHOD(reloadAppWithURLString:(NSString *)URLString moduleNamed:(NSString *)moduleName) { | |
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; | |
NSURL *JSBundleURL = [NSURL URLWithString:URLString]; | |
[delegate.viewController reloadWithJSBundleURL:JSBundleURL moduleNamed:moduleName]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment