-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodePush.js
46 lines (43 loc) · 1.26 KB
/
codePush.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {codePushKeys} from '../Constants/codePushKeys';
import {logToConsole} from './helpers';
function loadCodePushModule() {
const codePush = require('react-native-code-push');
return codePush;
}
export function codePushSync() {
return new Promise(function(resolve, reject) {
const codePush = loadCodePushModule();
checkCodePushUpdate().then(status => {
codePush
.sync({
checkFrequency: codePush.CheckFrequency.ON_APP_START,
installMode: codePush.InstallMode.IMMEDIATE,
deploymentKey: codePushKeys,
})
.then(result => {
resolve(result);
})
.catch(e => {
reject(e);
});
});
});
}
function checkCodePushUpdate() {
return new Promise(function(resolve, reject) {
const codePush = loadCodePushModule();
return codePush
.checkCodePushUpdate()
.then(syncStatus => {
// wait for the initial code sync to complete else we get flicker
// in the app when it updates after it has started up and is
// on the Home screen
resolve(syncStatus);
})
.catch(e => {
// this could happen if the app doesn't have connectivity
// just go ahead and start up as normal
reject(e);
});
});
}