@@ -95,12 +95,52 @@ function notifyApplicationReady() {
95
95
return NativeCodePush . notifyApplicationReady ( ) ;
96
96
}
97
97
98
+ function sync ( options = { } ) {
99
+ return new Promise ( ( resolve , reject ) => {
100
+ checkForUpdate ( )
101
+ . then ( ( remotePackage ) => {
102
+ if ( ! remotePackage ) {
103
+ resolve ( CodePush . SyncStatus . NO_UPDATE_AVAILABLE ) ;
104
+ }
105
+ else {
106
+ var dialogButtons = [
107
+ {
108
+ text : options . downloadButtonText || "Download" ,
109
+ onPress : ( ) => {
110
+ remotePackage . download ( )
111
+ . then ( ( localPackage ) => {
112
+ resolve ( CodePush . SyncStatus . APPLY_SUCCESS ) ;
113
+ localPackage . apply ( options . rollbackTImeout ) ;
114
+ } , reject ) ;
115
+ }
116
+ }
117
+ ] ;
118
+
119
+ if ( ! remotePackage . isMandatory ) {
120
+ dialogButtons . push ( {
121
+ text : options . cancelButtonText || "Cancel" ,
122
+ onPress : ( ) => resolve ( CodePush . SyncStatus . USER_CANCELLED )
123
+ } ) ;
124
+ }
125
+
126
+ React . AlertIOS . alert ( options . title || "Update available" , remotePackage . description , dialogButtons ) ;
127
+ }
128
+ } , reject ) ;
129
+ } ) ;
130
+ } ;
131
+
98
132
var CodePush = {
99
133
getConfiguration : getConfiguration ,
100
134
checkForUpdate : checkForUpdate ,
101
135
getCurrentPackage : getCurrentPackage ,
102
136
notifyApplicationReady : notifyApplicationReady ,
103
- setUpTestDependencies : setUpTestDependencies
137
+ setUpTestDependencies : setUpTestDependencies ,
138
+ sync : sync ,
139
+ SyncStatus : {
140
+ NO_UPDATE_AVAILABLE : 0 ,
141
+ APPLY_SUCCESS : 1 ,
142
+ USER_CANCELLED : 2
143
+ }
104
144
} ;
105
145
106
- module . exports = CodePush ;
146
+ module . exports = CodePush ;
0 commit comments