Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 575c7ab

Browse files
author
soliury
committed
code push sync only works in wifi networks
1 parent b7bd859 commit 575c7ab

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/layouts/Utils.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import React, {
44
StyleSheet,
55
Text,
66
StatusBar,
7-
AppState
87
} from 'react-native';
98
import Toast from '../components/base/Toast';
10-
import codePush from "react-native-code-push";
9+
import * as codePushUtils from '../utils/codePushSync';
1110
import 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

src/utils/codePushSync.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)