@@ -14,43 +14,35 @@ + (NSString *) getBundleFolderPath
14
14
return bundleFolder;
15
15
}
16
16
17
- + (NSString *) getBundlePath : ( NSString *) bundleName
17
+ + (NSString *) getBundlePath
18
18
{
19
19
NSString * bundleFolderPath = [self getBundleFolderPath ];
20
- NSString * appBundleName = [bundleName stringByAppendingString: @" .jsbundle" ] ;
20
+ NSString * appBundleName = @" main .jsbundle" ;
21
21
return [bundleFolderPath stringByAppendingPathComponent: appBundleName];
22
22
}
23
23
24
- + (NSURL *) getNativeBundleURL : ( NSString *) bundleName
24
+ + (NSURL *) getNativeBundleURL
25
25
{
26
- return [[NSBundle mainBundle ] URLForResource: bundleName withExtension: @" jsbundle" ];
26
+ return [[NSBundle mainBundle ] URLForResource: @" main " withExtension: @" jsbundle" ];
27
27
}
28
28
29
- + (NSURL *) appBundleUrl
30
- {
31
- return [self appBundleUrl: @" bundle"
32
- nativeBundleName: @" main" ];
33
- }
34
-
35
- + (NSURL *) appBundleUrl : (NSString *)bundleName
36
- nativeBundleName : (NSString *)nativeBundleName
29
+ + (NSURL *) getBundleUrl
37
30
{
38
31
NSFileManager *fileManager = [NSFileManager defaultManager ];
39
32
40
- NSString *bundlePath = [self getBundlePath: bundleName ];
33
+ NSString *bundlePath = [self getBundlePath ];
41
34
if ([fileManager fileExistsAtPath: bundlePath]) {
42
35
return [[NSURL alloc ] initFileURLWithPath: bundlePath];
43
36
} else {
44
- return [self getNativeBundleURL: nativeBundleName ];
37
+ return [self getNativeBundleURL ];
45
38
}
46
39
}
47
40
48
- + (void ) loadBundle : (NSString *)moduleName
49
- nativeBundleName : (NSString *)nativeBundleName
41
+ + (void ) loadBundle : (NSString *)rootComponent
50
42
{
51
43
dispatch_async (dispatch_get_main_queue (), ^{
52
- RCTRootView *rootView = [[RCTRootView alloc ] initWithBundleURL: [self appBundleUrl: moduleName nativeBundleName: nativeBundleName ]
53
- moduleName: moduleName
44
+ RCTRootView *rootView = [[RCTRootView alloc ] initWithBundleURL: [self getBundleUrl ]
45
+ moduleName: rootComponent
54
46
launchOptions: nil ];
55
47
56
48
UIViewController *rootViewController = [[UIViewController alloc ] init ];
@@ -59,57 +51,46 @@ + (void) loadBundle:(NSString*)moduleName
59
51
});
60
52
}
61
53
62
- RCT_EXPORT_METHOD (installUpdateFromUrl:(NSString *)updateUrl
63
- bundleName:(NSString *)bundleName
64
- nativeBundleName:(NSString *)nativeBundleName
65
- failureCallback:(RCTResponseSenderBlock)failureCallback
66
- successCallback:(RCTResponseSenderBlock)successCallback)
54
+ RCT_EXPORT_METHOD (getConfiguration:(RCTResponseSenderBlock)callback)
67
55
{
68
- NSError *parameterError;
69
- NSMutableDictionary *errorData;
70
- if (!updateUrl) {
71
- errorData = [NSMutableDictionary dictionary ];
72
- [errorData setValue: @" missing-updateUrl" forKey: NSLocalizedDescriptionKey ];
73
- } else if (!bundleName) {
74
- errorData = [NSMutableDictionary dictionary ];
75
- [errorData setValue: @" missing-bundleName" forKey: NSLocalizedDescriptionKey ];
76
- }
56
+ callback (@[[NSNull null ], [HybridMobileDeployConfig getConfiguration ]]);
57
+ }
77
58
78
- if (errorData) {
79
- parameterError = [NSError errorWithDomain: @" HybridMobileDeploy" code: 200 userInfo: errorData];
80
- NSDictionary *rctError = RCTMakeError (@" Error with input to installUpdateFromUrl" , parameterError, errorData);
81
- failureCallback (@[rctError]);
82
- } else {
83
- dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
84
- NSURL * url = [NSURL URLWithString: updateUrl];
85
- NSError *err;
59
+ RCT_EXPORT_METHOD (installUpdateFromUrl:(NSString *)updateUrl
60
+ callback:(RCTResponseSenderBlock)callback)
61
+ {
62
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
63
+ NSURL * url = [NSURL URLWithString: updateUrl];
64
+ NSError *err;
86
65
87
- NSString *updateContents = [[NSString alloc ] initWithContentsOfURL: url
88
- encoding: NSUTF8StringEncoding
89
- error: &err];
90
- if (err) {
91
- failureCallback (@[err]);
92
- } else {
93
- dispatch_async (dispatch_get_main_queue (), ^{
94
- NSError *saveError;
95
- NSString *bundleFolderPath = [HybridMobileDeploy getBundleFolderPath ];
96
- if (![[NSFileManager defaultManager ] fileExistsAtPath: bundleFolderPath]) {
97
- [[NSFileManager defaultManager ] createDirectoryAtPath: bundleFolderPath withIntermediateDirectories: YES attributes: nil error: &saveError];
98
- }
99
- [updateContents writeToFile: [HybridMobileDeploy getBundlePath: bundleName]
100
- atomically: YES
101
- encoding: NSUTF8StringEncoding
102
- error: &saveError];
103
- if (saveError) {
104
- failureCallback (@[saveError]);
105
- } else {
106
- [HybridMobileDeploy loadBundle: bundleName nativeBundleName: nativeBundleName];
107
- successCallback (@[]);
108
- }
109
- });
110
- }
111
- });
112
- }
66
+ NSString *updateContents = [[NSString alloc ] initWithContentsOfURL: url
67
+ encoding: NSUTF8StringEncoding
68
+ error: &err];
69
+
70
+ if (err) {
71
+ // TODO send download url
72
+ callback (@[RCTMakeError (@" Error downloading url" , err, [[NSDictionary alloc ] initWithObjectsAndKeys: updateUrl,@" updateUrl" , nil ])]);
73
+ } else {
74
+ dispatch_async (dispatch_get_main_queue (), ^{
75
+ NSError *saveError;
76
+ NSString *bundleFolderPath = [HybridMobileDeploy getBundleFolderPath ];
77
+ if (![[NSFileManager defaultManager ] fileExistsAtPath: bundleFolderPath]) {
78
+ [[NSFileManager defaultManager ] createDirectoryAtPath: bundleFolderPath withIntermediateDirectories: YES attributes: nil error: &saveError];
79
+ }
80
+ [updateContents writeToFile: [HybridMobileDeploy getBundlePath ]
81
+ atomically: YES
82
+ encoding: NSUTF8StringEncoding
83
+ error: &saveError];
84
+ if (saveError) {
85
+ // TODO send file path
86
+ callback (@[RCTMakeError (@" Error saving file" , err, [[NSDictionary alloc ] initWithObjectsAndKeys: [HybridMobileDeploy getBundlePath ],@" bundlePath" , nil ])]);
87
+ } else {
88
+ [HybridMobileDeploy loadBundle: [HybridMobileDeployConfig getRootComponent ]];
89
+ callback (@[[NSNull null ]]);
90
+ }
91
+ });
92
+ }
93
+ });
113
94
}
114
95
115
96
@end
0 commit comments