This repository was archived by the owner on Jan 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,10 +4,9 @@ import React, {
44 StyleSheet ,
55 Text ,
66 StatusBar ,
7- AppState
87} from 'react-native' ;
98import Toast from '../components/base/Toast' ;
10- import codePush from "react-native-code-push" ;
9+ import * as codePushUtils from '../utils/codePushSync' ;
1110import secretKey from '../testKey' ;
1211
1312
@@ -20,12 +19,7 @@ class Utils extends Component {
2019 // actions.toast('登陆成功');
2120 // });
2221 // }
23- if ( ! __DEV__ ) {
24- codePush . sync ( ) ;
25- AppState . addEventListener ( "change" , ( newState ) => {
26- newState === "active" && codePush . sync ( ) ;
27- } ) ;
28- }
22+ codePushUtils . init ( ) ;
2923 }
3024
3125
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