Skip to content

Commit 8dcc8a0

Browse files
Support installmodes 'on_next_resume' and 'immediate' #6
1 parent b5caa38 commit 8dcc8a0

12 files changed

+12886
-101
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,29 @@ import { CodePush } from "nativescript-code-push";
107107

108108
// and at some point in your app:
109109
CodePush.sync({
110-
deploymentKey: "your-deployment-key"
110+
deploymentKey: "your-deployment-key" // note that this key depends on the platform you're running on (see the example below)
111111
});
112112
```
113113

114-
If you have an iOS and Android app, and want some feedback during the sync, you can use this more elaborate version instead:
114+
There's a few things you can configure - this example has all the possible options:
115115

116116
```typescript
117117
import { CodePush, InstallMode, SyncStatus } from "nativescript-code-push";
118118
import { isIOS } from "tns-core-modules/platform";
119119

120120
CodePush.sync({
121121
deploymentKey: isIOS ? "your-ios-deployment-key" : "your-android-deployment-key",
122-
installMode: InstallMode.ON_NEXT_RESTART, // this is the default, and at this moment the only option
123-
serverUrl: "https://your-backend.server" // by default this is our shared cloud hosted backend server
122+
installMode: InstallMode.ON_NEXT_RESTART, // this is the default install mode; the app updates upon the next cold boot (unless the --mandatory flag was specified while pushing the update)
123+
mandatoryInstallMode: InstallMode.IMMEDIATE, // the default is InstallMode.ON_NEXT_RESUME which doesn't bother the user as long as the app is in the foreground. InstallMode.IMMEDIATE shows an installation prompt. Don't use that for iOS AppStore distributions because Apple doesn't want you to.
124+
serverUrl: "https://your-backend.server", // by default this is our shared cloud hosted backend server, so you probably want to leave this out
125+
updateDialog: { // only used for InstallMode.IMMEDIATE
126+
updateTitle: "Please restart the app", // an optional title shown in the update dialog
127+
optionalUpdateMessage: "Optional update msg", // a message shown for non-"--mandatory" releases
128+
mandatoryUpdateMessage: "Mandatory update msg", // a message shown for "--mandatory" releases
129+
optionalIgnoreButtonLabel: "Later", // if a user wants to continue their session, the update will be installed on next resume
130+
mandatoryContinueButtonLabel: isIOS ? "Exit now" : "Restart now", // On Android we can kill and restart the app, but on iOS that's not possible so the user has to manually restart it. That's why we provide a different label in this example.
131+
appendReleaseDescription: true // appends the description you (optionally) provided when releasing a new version to CodePush
132+
}
124133
}, (syncStatus: SyncStatus): void => {
125134
console.log("CodePush syncStatus: " + syncStatus);
126135
if (syncStatus === SyncStatus.UP_TO_DATE) {
@@ -131,8 +140,7 @@ CodePush.sync({
131140
});
132141
```
133142

134-
It's recommended to check for updates more than once in a cold boot cycle, so it may be easiest to
135-
tie this check to the `resume` event:
143+
It's recommended to check for updates more than once in a cold boot cycle, so it may be easiest to tie this check to the `resume` event:
136144

137145
```typescript
138146
import * as application from "tns-core-modules/application";
@@ -151,18 +159,18 @@ The easiest way to do this is to use the `release-nativescript` command in our C
151159

152160
|param|alias|default|description
153161
|---|---|---|---
154-
|deploymentName|d|Staging|Deploy to either "Staging" or "Production".
162+
|deploymentName|d|"Staging"|Deploy to either "Staging" or "Production".
155163
|description|des||Description of the changes made to the app with this release.
156164
|targetBinaryVersion|t||Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3).
157-
|rollout|r|100%|Percentage of users this release should be available to. The `%` sign is optional.
165+
|mandatory|m|not set, so "optional"|This specifies whether the update should be considered mandatory or not (e.g. it includes a critical security fix). This attribute is simply round tripped to the client, who can then decide if and how they would like to enforce it. This is flag, so its absence indicates an optional release.
158166

159167
### iOS
160168

161169
```shell
162170
nativescript-code-push release-nativescript <codepush-ios-appname> ios # deploy to Staging
163171
nativescript-code-push release-nativescript <codepush-ios-appname> ios --d Production # deploy to Production (default: Staging)
164172
nativescript-code-push release-nativescript <codepush-ios-appname> ios --targetBinaryVersion ~1.0.0 # release to users running any 1.x version (default: the exact version in Info.plist)
165-
nativescript-code-push release-nativescript <codepush-ios-appname> ios --rollout 25 --description "My awesome iOS version" # percentage of users this release should be immediately available to (default: 100)
173+
nativescript-code-push release-nativescript <codepush-ios-appname> ios --mandatory --description "My mandatory iOS version" # mandatory release for iOS
166174
```
167175

168176
### Android
@@ -189,8 +197,5 @@ nativescript-code-push deployment history <codepush-ios-appname> Staging
189197
You may want to play with CodePush before using it in production (smart move!).
190198
Perform these steps once you've pushed an update and added the `sync` command to your app:
191199

192-
- `$ tns run <platform>`. On an iOS device add the `--release` flag so LiveSync doesn't interfere.
200+
- `$ tns run <platform>`. On an iOS *device* add the `--release` flag so LiveSync doesn't interfere.
193201
- kill and restart the app after the update is installed
194-
195-
## Future enhancements
196-
Support on-resume reloads. I haven't investigated this possibility yet. If it can be pulled off we'll add an option to the `sync` command.

demo/demoapp/main-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<StackLayout class="p-20">
33

44
<!-- you can toggle these labels when building/releasing -->
5-
<!-- <Label text="I'm CODEPUSH version v5" class="t-20 text-center c-orange" textWrap="true"/>-->
5+
<!-- <Label text="I'm CODEPUSH iOS version v7 (mandatory)" class="t-20 text-center c-orange" textWrap="true"/>-->
66
<Label text="I'm the APPSTORE version" class="t-20 text-center c-orange" textWrap="true"/>
77

88
<Label text="{{ message }}" class="t-20 m-30 text-center c-black" textWrap="true"/>

demo/demoapp/main-view-model.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ export class HelloWorldModel extends Observable {
1919
super();
2020
this.codePush = new CodePush();
2121

22-
// let's immediately check for updates on the server
23-
this.syncWithCodePushServer();
24-
25-
// and also check for updates whenever the application is resumed
26-
application.on(application.resumeEvent, () => {
27-
this.syncWithCodePushServer();
28-
});
22+
// Check for updates when the app is loaded or resumed
23+
application.on(application.resumeEvent, () => this.syncWithCodePushServer());
2924
}
3025

3126
private syncWithCodePushServer(): void {
3227
this.set("message", "Querying CodePush..");
33-
let that = this;
34-
3528
CodePush.sync({
3629
deploymentKey: isIOS ? HelloWorldModel.CODEPUSH_IOS_STAGING_KEY : HelloWorldModel.CODEPUSH_ANDROID_STAGING_KEY,
37-
installMode: InstallMode.ON_NEXT_RESTART, // has not effect currently, always using ON_NEXT_RESTART
38-
mandatoryInstallMode: InstallMode.IMMEDIATE // has not effect currently, always using ON_NEXT_RESTART
30+
installMode: InstallMode.ON_NEXT_RESTART, // default InstallMode.ON_NEXT_RESTART
31+
mandatoryInstallMode: InstallMode.IMMEDIATE, // default InstallMode.ON_NEXT_RESUME
32+
updateDialog: { // only used for InstallMode.IMMEDIATE
33+
optionalUpdateMessage: "Optional update msg",
34+
updateTitle: "Please restart the app",
35+
mandatoryUpdateMessage: "Mandatory update msg",
36+
optionalIgnoreButtonLabel: "Later",
37+
mandatoryContinueButtonLabel: isIOS ? "Exit now" : "Restart now",
38+
appendReleaseDescription: true // appends the description you (optionally) provided when releasing a new version to CodePush
39+
}
3940
}, (syncStatus: SyncStatus): void => {
40-
console.log("syncStatus: " + syncStatus);
4141
if (syncStatus === SyncStatus.UP_TO_DATE) {
42-
that.set("message", "CodePush: up to date");
42+
this.set("message", "CodePush: up to date");
4343
} else if (syncStatus === SyncStatus.UPDATE_INSTALLED) {
44-
that.set("message", "CodePush: update installed, kill/restart your app to see the changes");
44+
this.set("message", "CodePush: update installed");
4545
}
4646
});
4747
}

0 commit comments

Comments
 (0)