Example #1
0
File: index.js Project: Almax/dev
 async componentDidMount() {
   if(Platform.OS === 'ios' && false) {
     let result = await codePush.checkForUpdate();
     if(result) {
       codePush.sync({ 
          updateDialog: {
           title: "发现婚格有更新",
           optionalUpdateMessage: "小主,app更新啦~快来更新",
           optionalInstallButtonLabel: "安装",
           optionalIgnoreButtonLabel: "下次再说",
           appendReleaseDescription: true,
           descriptionPrefix: "\n\n本次更新:\n"   
          },
         installMode: codePush.InstallMode.IMMEDIATE 
       }, (status) => {
         switch (status) {
           case codePush.SyncStatus.DOWNLOADING_PACKAGE:
               this.setState({ finished: false });
               break;
           case codePush.SyncStatus.INSTALLING_UPDATE:
               
               break;
           case codePush.SyncStatus.UPDATE_INSTALLED:
               Alert.alert("更新完成", "正在重启");
               break;
           case codePush.SyncStatus.SYNC_IN_PROGRESS: 
               
               break;
         }
       }, (progress) => {
         this.setState({ progress });
       });
     }
   }
 }
		codePush.getUpdateMetadata(UpdateState.PENDING).then((localUpdate) => {
			cachedVersion = localUpdate;
			if (localUpdate) return resolve(localUpdate);
			// Queries the CodePush service to see whether the configured app deployment has an update available.
			// By default, it will use the deployment key that is configured in your Info.plist file (iOS), or MainActivity.java file (Android)
			codePush.checkForUpdate().then((remoteUpdate) => {
				cachedVersion = remoteUpdate;
				if (!remoteUpdate) return resolve(null);
				/*
				remoteUpdate === null can be due to the following reasons:
				- No CodePush updates were installed since the last time disallowRestart was called, and therefore, there isn't any need to restart anyways.
				- There is currently a pending CodePush update, but it was installed via InstallMode.ON_NEXT_RESUME and the app hasn't been put into the background yet, and therefore, there isn't a need to programmatically restart yet.
				- The currently running app already has the latest release from the configured deployment, and therefore, doesn't need it again.
				- No calls to restartApp were made since the last time disallowRestart was called.
				*/
				remoteUpdate
				// downloadProgressCallback is periodically called with a DownloadProgress object
				// than looks like { totalBytes: Number, receivedBytes: Number }
				.download(downloadProgressCallback)
				.then(resolve);
			});
		});
 async () => {
   let update = await CodePush.checkForUpdate();
   assert(!update, "checkForUpdate should not return an update if there is none on the server");
 }
 async () => {
   let update = await CodePush.checkForUpdate();
   assert(!update, "checkForUpdate should not return an update if remote package is of a different binary version");
 }
 async () => {
   let update = await CodePush.checkForUpdate(deploymentKey);
   assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote(), failedInstall: false, deploymentKey }), "checkForUpdate did not return the update from the server");
 }