@@ -13,6 +13,8 @@ @implementation CodePush {
13
13
14
14
RCT_EXPORT_MODULE ()
15
15
16
+ #pragma mark - Private constants
17
+
16
18
static BOOL needToReportRollback = NO ;
17
19
static BOOL isRunningBinaryVersion = NO ;
18
20
static BOOL testConfigurationFlag = NO ;
@@ -38,9 +40,8 @@ @implementation CodePush {
38
40
static NSString *const PackageHashKey = @" packageHash" ;
39
41
static NSString *const PackageIsPendingKey = @" isPending" ;
40
42
41
- @synthesize bridge = _bridge;
43
+ # pragma mark - Public Obj-C API
42
44
43
- // Public Obj-C API (see header for method comments)
44
45
+ (NSURL *)bundleURL
45
46
{
46
47
return [self bundleURLForResource: @" main" ];
@@ -91,7 +92,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
91
92
#ifndef DEBUG
92
93
[CodePush clearUpdates ];
93
94
#endif
94
-
95
+
95
96
NSLog (logMessageFormat, binaryJsBundleUrl);
96
97
isRunningBinaryVersion = YES ;
97
98
return binaryJsBundleUrl;
@@ -113,7 +114,12 @@ + (BOOL)isUsingTestConfiguration
113
114
return testConfigurationFlag;
114
115
}
115
116
116
- /*
117
+ + (void )setDeploymentKey : (NSString *)deploymentKey
118
+ {
119
+ [CodePushConfig current ].deploymentKey = deploymentKey;
120
+ }
121
+
122
+ /*
117
123
* This is used to enable an environment in which tests can be run.
118
124
* Specifically, it flips a boolean flag that causes bundles to be
119
125
* saved to a test folder and enables the ability to modify
@@ -134,8 +140,9 @@ + (void)clearUpdates
134
140
[self removeFailedUpdates ];
135
141
}
136
142
143
+ #pragma mark - Private API methods
137
144
138
- // Private API methods
145
+ @synthesize bridge = _bridge;
139
146
140
147
/*
141
148
* This method is used by the React Native bridge to allow
@@ -147,11 +154,11 @@ - (NSDictionary *)constantsToExport
147
154
{
148
155
// Export the values of the CodePushInstallMode enum
149
156
// so that the script-side can easily stay in sync
150
- return @{
151
- @" codePushInstallModeOnNextRestart" :@(CodePushInstallModeOnNextRestart),
152
- @" codePushInstallModeImmediate" : @(CodePushInstallModeImmediate),
153
- @" codePushInstallModeOnNextResume" : @(CodePushInstallModeOnNextResume)
154
- };
157
+ return @{
158
+ @" codePushInstallModeOnNextRestart" :@(CodePushInstallModeOnNextRestart),
159
+ @" codePushInstallModeImmediate" : @(CodePushInstallModeImmediate),
160
+ @" codePushInstallModeOnNextResume" : @(CodePushInstallModeOnNextResume)
161
+ };
155
162
};
156
163
157
164
- (void )dealloc
@@ -257,12 +264,12 @@ - (BOOL)isPendingUpdate:(NSString*)packageHash
257
264
{
258
265
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
259
266
NSDictionary *pendingUpdate = [preferences objectForKey: PendingUpdateKey];
260
-
267
+
261
268
// If there is a pending update whose "state" isn't loading, then we consider it "pending".
262
269
// Additionally, if a specific hash was provided, we ensure it matches that of the pending update.
263
270
BOOL updateIsPending = pendingUpdate &&
264
- [pendingUpdate[PendingUpdateIsLoadingKey] boolValue ] == NO &&
265
- (!packageHash || [pendingUpdate[PendingUpdateHashKey] isEqualToString: packageHash]);
271
+ [pendingUpdate[PendingUpdateIsLoadingKey] boolValue ] == NO &&
272
+ (!packageHash || [pendingUpdate[PendingUpdateHashKey] isEqualToString: packageHash]);
266
273
267
274
return updateIsPending;
268
275
}
@@ -380,41 +387,41 @@ - (void)savePendingUpdate:(NSString *)packageHash
380
387
[preferences synchronize ];
381
388
}
382
389
383
- // JavaScript-exported module methods
390
+ # pragma mark - JavaScript-exported module methods
384
391
385
392
/*
386
393
* This is native-side of the RemotePackage.download method
387
394
*/
388
395
RCT_EXPORT_METHOD (downloadUpdate:(NSDictionary *)updatePackage
389
- resolver:(RCTPromiseResolveBlock)resolve
390
- rejecter:(RCTPromiseRejectBlock)reject)
396
+ resolver:(RCTPromiseResolveBlock)resolve
397
+ rejecter:(RCTPromiseRejectBlock)reject)
391
398
{
392
399
[CodePushPackage downloadPackage: updatePackage
393
- // The download is progressing forward
394
- progressCallback: ^(long long expectedContentLength, long long receivedContentLength) {
395
- // Notify the script-side about the progress
396
- [self .bridge.eventDispatcher
397
- sendDeviceEventWithName: @" CodePushDownloadProgress"
398
- body: @{
399
- @" totalBytes" :[NSNumber numberWithLongLong: expectedContentLength],
400
- @" receivedBytes" :[NSNumber numberWithLongLong: receivedContentLength]
401
- }];
402
- }
403
- // The download completed
404
- doneCallback: ^{
405
- NSError *err;
406
- NSDictionary *newPackage = [CodePushPackage getPackage: updatePackage[PackageHashKey] error: &err];
407
-
408
- if (err) {
409
- return reject (err);
410
- }
411
-
412
- resolve (newPackage);
413
- }
414
- // The download failed
415
- failCallback: ^(NSError *err) {
416
- reject (err);
417
- }];
400
+ // The download is progressing forward
401
+ progressCallback: ^(long long expectedContentLength, long long receivedContentLength) {
402
+ // Notify the script-side about the progress
403
+ [self .bridge.eventDispatcher
404
+ sendDeviceEventWithName: @" CodePushDownloadProgress"
405
+ body: @{
406
+ @" totalBytes" :[NSNumber numberWithLongLong: expectedContentLength],
407
+ @" receivedBytes" :[NSNumber numberWithLongLong: receivedContentLength]
408
+ }];
409
+ }
410
+ // The download completed
411
+ doneCallback: ^{
412
+ NSError *err;
413
+ NSDictionary *newPackage = [CodePushPackage getPackage: updatePackage[PackageHashKey] error: &err];
414
+
415
+ if (err) {
416
+ return reject (@" " , @" " , err);
417
+ }
418
+
419
+ resolve (newPackage);
420
+ }
421
+ // The download failed
422
+ failCallback: ^(NSError *err) {
423
+ reject (@" " , @" " , err);
424
+ }];
418
425
}
419
426
420
427
/*
@@ -424,7 +431,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
424
431
* app version, as well as the deployment key that was configured in the Info.plist file.
425
432
*/
426
433
RCT_EXPORT_METHOD (getConfiguration:(RCTPromiseResolveBlock)resolve
427
- rejecter:(RCTPromiseRejectBlock)reject)
434
+ rejecter:(RCTPromiseRejectBlock)reject)
428
435
{
429
436
resolve ([[CodePushConfig current ] configuration ]);
430
437
}
@@ -433,21 +440,21 @@ - (void)savePendingUpdate:(NSString *)packageHash
433
440
* This method is the native side of the CodePush.getCurrentPackage method.
434
441
*/
435
442
RCT_EXPORT_METHOD (getCurrentPackage:(RCTPromiseResolveBlock)resolve
436
- rejecter:(RCTPromiseRejectBlock)reject)
443
+ rejecter:(RCTPromiseRejectBlock)reject)
437
444
{
438
445
dispatch_async (dispatch_get_main_queue (), ^{
439
446
NSError *error;
440
447
NSMutableDictionary *package = [[CodePushPackage getCurrentPackage: &error] mutableCopy ];
441
448
442
449
if (error) {
443
- reject (error);
450
+ reject (@" " , @" " , error);
444
451
}
445
452
446
453
// Add the "isPending" virtual property to the package at this point, so that
447
454
// the script-side doesn't need to immediately call back into native to populate it.
448
455
BOOL isPendingUpdate = [self isPendingUpdate: [package objectForKey: PackageHashKey]];
449
456
[package setObject: @(isPendingUpdate) forKey: PackageIsPendingKey];
450
-
457
+
451
458
resolve (package);
452
459
});
453
460
}
@@ -456,17 +463,17 @@ - (void)savePendingUpdate:(NSString *)packageHash
456
463
* This method is the native side of the LocalPackage.install method.
457
464
*/
458
465
RCT_EXPORT_METHOD (installUpdate:(NSDictionary *)updatePackage
459
- installMode:(CodePushInstallMode)installMode
460
- resolver:(RCTPromiseResolveBlock)resolve
461
- rejecter:(RCTPromiseRejectBlock)reject)
466
+ installMode:(CodePushInstallMode)installMode
467
+ resolver:(RCTPromiseResolveBlock)resolve
468
+ rejecter:(RCTPromiseRejectBlock)reject)
462
469
{
463
470
dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
464
471
NSError *error;
465
472
[CodePushPackage installPackage: updatePackage
466
473
error: &error];
467
474
468
475
if (error) {
469
- reject (error);
476
+ reject (@" " , @" " , error);
470
477
} else {
471
478
[self savePendingUpdate: updatePackage[PackageHashKey]
472
479
isLoading: NO ];
@@ -492,8 +499,8 @@ - (void)savePendingUpdate:(NSString *)packageHash
492
499
* module, and is only used internally to populate the RemotePackage.failedInstall property.
493
500
*/
494
501
RCT_EXPORT_METHOD (isFailedUpdate:(NSString *)packageHash
495
- resolve:(RCTPromiseResolveBlock)resolve
496
- reject:(RCTPromiseRejectBlock)reject)
502
+ resolve:(RCTPromiseResolveBlock)resolve
503
+ reject:(RCTPromiseRejectBlock)reject)
497
504
{
498
505
BOOL isFailedHash = [self isFailedHash: packageHash];
499
506
resolve (@(isFailedHash));
@@ -504,14 +511,14 @@ - (void)savePendingUpdate:(NSString *)packageHash
504
511
* module, and is only used internally to populate the LocalPackage.isFirstRun property.
505
512
*/
506
513
RCT_EXPORT_METHOD (isFirstRun:(NSString *)packageHash
507
- resolve:(RCTPromiseResolveBlock)resolve
508
- rejecter:(RCTPromiseRejectBlock)reject)
514
+ resolve:(RCTPromiseResolveBlock)resolve
515
+ rejecter:(RCTPromiseRejectBlock)reject)
509
516
{
510
517
NSError *error;
511
518
BOOL isFirstRun = _isFirstRunAfterUpdate
512
- && nil != packageHash
513
- && [packageHash length ] > 0
514
- && [packageHash isEqualToString: [CodePushPackage getCurrentPackageHash: &error]];
519
+ && nil != packageHash
520
+ && [packageHash length ] > 0
521
+ && [packageHash isEqualToString: [CodePushPackage getCurrentPackageHash: &error]];
515
522
516
523
resolve (@(isFirstRun));
517
524
}
@@ -520,18 +527,18 @@ - (void)savePendingUpdate:(NSString *)packageHash
520
527
* This method is the native side of the CodePush.notifyApplicationReady() method.
521
528
*/
522
529
RCT_EXPORT_METHOD (notifyApplicationReady:(RCTPromiseResolveBlock)resolve
523
- rejecter:(RCTPromiseRejectBlock)reject)
530
+ rejecter:(RCTPromiseRejectBlock)reject)
524
531
{
525
532
[CodePush removePendingUpdate ];
526
533
resolve ([NSNull null ]);
527
534
}
528
535
529
536
/*
530
- * This method is checks if a new status update exists (new version was installed,
537
+ * This method is checks if a new status update exists (new version was installed,
531
538
* or an update failed) and return its details (version label, status).
532
539
*/
533
540
RCT_EXPORT_METHOD (getNewStatusReport:(RCTPromiseResolveBlock)resolve
534
- rejecter:(RCTPromiseRejectBlock)reject)
541
+ rejecter:(RCTPromiseRejectBlock)reject)
535
542
{
536
543
if (needToReportRollback) {
537
544
// Check if there was a rollback that was not yet reported
@@ -589,7 +596,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
589
596
/*
590
597
* This method is the native side of the CodePush.downloadAndReplaceCurrentBundle()
591
598
* method, which replaces the current bundle with the one downloaded from
592
- * removeBundleUrl. It is only to be used during tests and no-ops if the test
599
+ * removeBundleUrl. It is only to be used during tests and no-ops if the test
593
600
* configuration flag is not set.
594
601
*/
595
602
RCT_EXPORT_METHOD (downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl)
@@ -599,4 +606,4 @@ - (void)savePendingUpdate:(NSString *)packageHash
599
606
}
600
607
}
601
608
602
- @end
609
+ @end
0 commit comments