-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (42 loc) · 1.26 KB
/
index.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
47
48
49
50
51
import { NativeModules, Platform } from 'react-native';
const isAndroid = Platform.OS === 'android';
const PlayServices = isAndroid ? NativeModules.PlayServices : {};
PlayServices.GooglePlayServicesStatus = {
AVAILABLE: 10,
GMS_DISABLED: 20,
GMS_NEED_UPDATE: 21,
INVALID: 30
};
PlayServices.checkPlayServicesStatus = isAndroid
? PlayServices.checkPlayServicesStatus
: async () => PlayServices.GooglePlayServicesStatus.AVAILABLE;
PlayServices.goToSetting = isAndroid
? PlayServices.goToSetting
: async () => {};
PlayServices.goToMarket = isAndroid
? PlayServices.goToMarket
: async () => {};
PlayServices.sync = async ({
onGmsDisabled = PlayServices.goToSetting,
onGmsNeedUpdate = PlayServices.goToMarket,
}) => {
if (!isAndroid) {
return;
}
const status = await PlayServices.checkPlayServicesStatus();
switch (status) {
case PlayServices.GooglePlayServicesStatus.GMS_DISABLED:
onGmsDisabled();
break;
case PlayServices.GooglePlayServicesStatus.GMS_NEED_UPDATE:
onGmsNeedUpdate();
break;
case PlayServices.GooglePlayServicesStatus.AVAILABLE:
break;
default:
const error = new Error(`Unhandled type: ${status}`);
console.error(error);
throw error;
}
};
export default PlayServices;