Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit bd41824

Browse files
committed
save packages on install, query updates with current package
1 parent 27df072 commit bd41824

File tree

6 files changed

+94
-16
lines changed

6 files changed

+94
-16
lines changed

Examples/HybridMobileDeployCompanion/iOS/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3333
* on the same Wi-Fi network.
3434
*/
3535

36-
//jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
36+
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
3737

3838
/**
3939
* OPTION 2
@@ -45,7 +45,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4545
* see http://facebook.github.io/react-native/docs/runningondevice.html
4646
*/
4747

48-
jsCodeLocation = [HybridMobileDeploy getBundleUrl];
48+
//jsCodeLocation = [HybridMobileDeploy getBundleUrl];
4949

5050
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
5151
moduleName:@"HybridMobileDeployCompanion"

Examples/HybridMobileDeployCompanion/iOS/Info.plist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
<key>NSLocationWhenInUseUsageDescription</key>
4040
<string></string>
4141
<key>CodePushDeploymentKey</key>
42-
<string>deployment-key-here</string>
42+
<string>b6883b8f-3e7b-4e48-98b1-ec509dc22aaa</string>
43+
<key>CodePushServerUrl</key>
44+
<string>http://ryuyu-test.azurewebsites.net/</string>
4345
</dict>
4446
</plist>

Examples/HybridMobileDeployCompanion/react-packager-cache-5737493143262339187995942fd693ba

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

HybridMobileDeploy.ios.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var NativeHybridMobileDeploy = require('react-native').NativeModules.HybridMobileDeploy;
99
var requestFetchAdapter = require("./request-fetch-adapter.js");
1010
var semver = require('semver');
11-
var Sdk = require("hybrid-mobile-deploy-sdk/script/acquisition-sdk").AcquisitionManager;
11+
var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
1212
var sdk;
1313
var config;
1414

@@ -44,16 +44,26 @@ function queryUpdate(callback) {
4444
if (err) callback(err);
4545
getSdk(function(err, sdk) {
4646
if (err) callback(err);
47-
var pkg = {appVersion: configuration.appVersion};
48-
sdk.queryUpdateWithCurrentPackage(pkg, callback);
47+
NativeHybridMobileDeploy.getLocalPackage(function(err, localPackage) {
48+
if(err){
49+
console.log(err);
50+
var pkg = {appVersion: configuration.appVersion};
51+
sdk.queryUpdateWithCurrentPackage(pkg, callback);
52+
}else if(localPackage == null){
53+
var pkg = {appVersion: configuration.appVersion};
54+
sdk.queryUpdateWithCurrentPackage(pkg, callback);
55+
}else{
56+
sdk.queryUpdateWithCurrentPackage(localPackage, callback);
57+
}
58+
});
4959
});
5060
});
5161
}
5262

5363
function installUpdate(update) {
54-
getConfiguration(function(err, config) {
55-
NativeHybridMobileDeploy.installUpdateFromUrl(config.serverUrl + "acquire/" + config.deploymentKey, (err) => console.log(err));
56-
});
64+
// use the downloaded package info. native code will save the package info
65+
// so that the client knows what the current package version is.
66+
NativeHybridMobileDeploy.installUpdate(update, JSON.stringify(update), (err) => console.log(err));
5767
}
5868

5969
var HybridMobileDeploy = {

HybridMobileDeploy.m

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ @implementation HybridMobileDeploy
1010
+ (NSString *) getBundleFolderPath
1111
{
1212
NSString* home = NSHomeDirectory();
13-
NSString* bundleFolder = [home stringByAppendingPathComponent:@"HybridMobileDeploy"];
13+
NSString* bundleFolder = [home stringByAppendingPathComponent:@"HybridMobileDeploy/bundle"];
1414
return bundleFolder;
1515
}
1616

@@ -21,6 +21,21 @@ + (NSString *) getBundlePath
2121
return [bundleFolderPath stringByAppendingPathComponent:appBundleName];
2222
}
2323

24+
+ (NSString *) getPackageFolderPath
25+
{
26+
NSString* home = NSHomeDirectory();
27+
NSString* packageFolder = [home stringByAppendingPathComponent:@"HybridMobileDeploy/package"];
28+
return packageFolder;
29+
}
30+
31+
+ (NSString *) getPackagePath
32+
{
33+
NSString * packageFolderPath = [self getPackageFolderPath];
34+
NSString* appPackageName = @"localpackage.json";
35+
return [packageFolderPath stringByAppendingPathComponent:appPackageName];
36+
}
37+
38+
2439
+ (NSURL *) getNativeBundleURL
2540
{
2641
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
@@ -56,11 +71,12 @@ + (void) loadBundle:(NSString*)rootComponent
5671
callback(@[[NSNull null], [HybridMobileDeployConfig getConfiguration]]);
5772
}
5873

59-
RCT_EXPORT_METHOD(installUpdateFromUrl:(NSString*)updateUrl
74+
RCT_EXPORT_METHOD(installUpdate:(NSDictionary*)updatePackage
75+
packageJsonString:(NSString*) packageJsonString
6076
callback:(RCTResponseSenderBlock)callback)
6177
{
6278
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
63-
NSURL* url = [NSURL URLWithString:updateUrl];
79+
NSURL* url = [NSURL URLWithString:updatePackage[@"downloadUrl"]];
6480
NSError *err;
6581

6682
NSString *updateContents = [[NSString alloc] initWithContentsOfURL:url
@@ -69,7 +85,7 @@ + (void) loadBundle:(NSString*)rootComponent
6985

7086
if (err) {
7187
// TODO send download url
72-
callback(@[RCTMakeError(@"Error downloading url", err, [[NSDictionary alloc] initWithObjectsAndKeys:updateUrl,@"updateUrl", nil])]);
88+
callback(@[RCTMakeError(@"Error downloading url", err, [[NSDictionary alloc] initWithObjectsAndKeys:[url absoluteString],@"updateUrl", nil])]);
7389
} else {
7490
dispatch_async(dispatch_get_main_queue(), ^{
7591
NSError *saveError;
@@ -85,12 +101,61 @@ + (void) loadBundle:(NSString*)rootComponent
85101
// TODO send file path
86102
callback(@[RCTMakeError(@"Error saving file", err, [[NSDictionary alloc] initWithObjectsAndKeys:[HybridMobileDeploy getBundlePath],@"bundlePath", nil])]);
87103
} else {
88-
[HybridMobileDeploy loadBundle:[HybridMobileDeployConfig getRootComponent]];
89-
callback(@[[NSNull null]]);
104+
105+
// save the package info too
106+
NSString *packageFolderPath = [HybridMobileDeploy getPackageFolderPath];
107+
if (![[NSFileManager defaultManager] fileExistsAtPath:packageFolderPath]) {
108+
[[NSFileManager defaultManager] createDirectoryAtPath:packageFolderPath withIntermediateDirectories:YES attributes:nil error:&saveError];
109+
}
110+
[packageJsonString writeToFile:[HybridMobileDeploy getPackagePath]
111+
atomically:YES
112+
encoding:NSUTF8StringEncoding
113+
error:&saveError];
114+
115+
if (saveError) {
116+
callback(@[RCTMakeError(@"Error saving file", err, [[NSDictionary alloc] initWithObjectsAndKeys:[HybridMobileDeploy getPackagePath],@"packagePath", nil])]);
117+
} else {
118+
[HybridMobileDeploy loadBundle:[HybridMobileDeployConfig getRootComponent]];
119+
callback(@[[NSNull null]]);
120+
}
90121
}
91122
});
92123
}
93124
});
94125
}
95126

127+
128+
129+
RCT_EXPORT_METHOD(getLocalPackage: (RCTResponseSenderBlock)callback)
130+
{
131+
132+
NSString *path = [HybridMobileDeploy getPackagePath];
133+
134+
dispatch_async(dispatch_get_main_queue(), ^{
135+
136+
NSError* readError;
137+
138+
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&readError];
139+
if(readError){
140+
141+
callback(@[RCTMakeError(@"Error finding local package ", readError, [[NSDictionary alloc] initWithObjectsAndKeys:path,@"packagePath", nil]), [NSNull null]]);
142+
}else{
143+
NSError * parseError;
144+
NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
145+
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
146+
options:kNilOptions
147+
error:&parseError];
148+
if(parseError){
149+
callback(@[RCTMakeError(@"Error parsing contents of local package ", parseError, [[NSDictionary alloc] initWithObjectsAndKeys:path,@"packagePath", nil]), [NSNull null]]);
150+
}else{
151+
callback(@[[NSNull null], json]);
152+
}
153+
154+
}
155+
156+
});
157+
158+
159+
}
160+
96161
@end

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "HybridMobileDeploy.ios.js",
55
"keywords": "react-native",
66
"dependencies": {
7-
"hybrid-mobile-deploy-sdk": "file:../website/sdk/bin",
7+
"code-push": "file:../website/sdk/bin",
88
"semver": "^4.3.6"
99
},
1010
"devDependencies": {

0 commit comments

Comments
 (0)