forked from rnplay/rnplay-native-deprecated
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppReloader.m
More file actions
60 lines (48 loc) · 1.93 KB
/
AppReloader.m
File metadata and controls
60 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// AppReloader.m
// RNPlayNative
//
// Created by Dave Sibiski on 6/2/15.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "AppReloader.h"
#import "AppDelegate.h"
#import "ViewController.h"
@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', 'Sample App')
*/
RCT_EXPORT_METHOD(reloadAppWithURLString:(NSString *)URLString moduleNamed:(NSString *)moduleName appName:(NSString *)appName)
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSURL *JSBundleURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?platform=ios", URLString]];
@try {
ViewController *appViewController = [[ViewController alloc] init];
[appViewController reloadWithJSBundleURL:JSBundleURL moduleNamed:moduleName appName:appName];
delegate.appViewController = appViewController;
delegate.shouldRotate = YES;
[UIView transitionWithView:delegate.window
duration:kFlipTransitionDuration
options:kFlipTransitionType
animations:^{
delegate.window.rootViewController = appViewController;
}
completion:NULL];
}
@catch (NSException *exception) {
NSLog(@"exception: %@", exception);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!"
message:@"Sorry, this app doesn't work! Looks like someone needs to brush up on their JavaScript! :p"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[alert show];
}
}
@end