This repository was archived by the owner on Jan 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +33
-8
lines changed Expand file tree Collapse file tree 2 files changed +33
-8
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,9 @@ import React, {
4
4
StyleSheet ,
5
5
Text ,
6
6
StatusBar ,
7
- AppState
8
7
} from 'react-native' ;
9
8
import Toast from '../components/base/Toast' ;
10
- import codePush from "react-native-code-push" ;
9
+ import * as codePushUtils from '../utils/codePushSync' ;
11
10
import secretKey from '../testKey' ;
12
11
13
12
@@ -20,12 +19,7 @@ class Utils extends Component {
20
19
// actions.toast('登陆成功');
21
20
// });
22
21
// }
23
- if ( ! __DEV__ ) {
24
- codePush . sync ( ) ;
25
- AppState . addEventListener ( "change" , ( newState ) => {
26
- newState === "active" && codePush . sync ( ) ;
27
- } ) ;
28
- }
22
+ codePushUtils . init ( ) ;
29
23
}
30
24
31
25
Original file line number Diff line number Diff line change
1
+ import React , {
2
+ NetInfo ,
3
+ AppState ,
4
+ Platform
5
+ } from 'react-native' ;
6
+ import codePush from 'react-native-code-push' ;
7
+
8
+
9
+ export function shouldSync ( ) {
10
+ return NetInfo
11
+ . fetch ( )
12
+ . then ( ( reach => {
13
+ if ( __DEV__ ) return false ;
14
+ if ( Platform . OS === 'ios' ) {
15
+ return reach === 'wifi' ;
16
+ }
17
+ else {
18
+ return [ 'WIFI' , 'VPN' ] . indexOf ( reach ) > - 1 ;
19
+ }
20
+ } ) ) ;
21
+ }
22
+
23
+
24
+ export function init ( ) {
25
+ shouldSync ( ) . done ( ( shouldSync ) => shouldSync && codePush . sync ( ) ) ;
26
+ AppState . addEventListener ( "change" , ( newState ) => {
27
+ if ( newState === "active" ) {
28
+ shouldSync ( ) . done ( ( shouldSync ) => shouldSync && codePush . sync ( ) ) ;
29
+ }
30
+ } ) ;
31
+ }
You can’t perform that action at this time.
0 commit comments