EN | KO
This library is made based on React Native 0.60.5+
. It's not recommended for under 0.60.5
, so upgrade your React Native version to 0.60.5
or later.
React Native Official Docs - Upgrading to new React Native versions
This library helps using Google Play Services API in React Native.
- Check whether Google Play Services is available
- Go to the Settings page to enable Google Play Services
- Go to the Play Store link to update Google Play Services
$ npm install react-native-play-services --save
or,
$ yarn add react-native-play-services
- Open
android/app/src/main/java/[...]/MainApplication.java
.
- Put
import io.humanscape.opensources.playservices.PlayServicesPackage;
at the top of file. - Add
new PlayServicesPackage()
to returning array ofgetPackages()
method.
- Add these lines to
android/settings.gradle
.include ':react-native-play-services' project(':react-native-play-services').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-play-services/android')
- Add this line to
dependencies
scope inandroid/app/build.gradle
.:compile project(':react-native-play-services')
import PlayServices from 'react-native-play-services';
// Full-set API
PlayServices.sync();
// Customizable API
(async () => {
const status = await PlayServices.checkPlayServicesStatus();
switch (status) {
case PlayServices.GooglePlayServicesStatus.GMS_DISABLED:
PlayServices.goToSetting();
break;
// handle anything.
}
})();
-
Constants
GooglePlayServicesStatus
GooglePlayServicesStatus.AVAILABLE
- Google Play Services is available.
GooglePlayServicesStatus.GMS_DISABLED
- Google Play Services is disabled.
- Need to enable at app settings.
GooglePlayServicesStatus.GMS_NEED_UPDATE
- Google Play Services is outdated.
- Need to update at Play Store.
GooglePlayServicesStatus.INVALID
- Unable to configure Google Play Services.
-
Functions
sync()
-
sync: (params: { onGmsDisabled?: () => {}, onGmsNeedUpdate?: () => {} }) => Promise<void>;
- Performs all actions for keeping Google Play Services status up to date.
- If
onGmsDisabled
is not specified, it will executegoToSettings()
. - If
onGmsNeedUpdate
is not specified, it will executegoToMarket()
.
-
checkPlayServicesStatus()
-
checkPlayServicesStatus: () => Promise<GooglePlayServicesStatus>;
- Checks Google Play Services status, and return
GooglePlayServicesStatus
.
-
goToSetting()
-
goToSetting: () => Promise<void>;
- Opens Setting page to enable Google Play Services.
-
goToMarket()
-
goToMarket: () => Promise<void>;
- Opens Play Store link to update Google Play Services.
-