Skip to content

DenSakhon/react-native-play-services

 
 

Repository files navigation

react-native-play-services

EN | KO

NPM LICENSE Stars Actions Status

Notes

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

Introduction

This library helps using Google Play Services API in React Native.

Features

  • 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

Install

Install via npm or yarn

$ npm install react-native-play-services --save

or,

$ yarn add react-native-play-services

Manual Install

  1. 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 of getPackages() method.
  1. 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')
  2. Add this line to dependencies scope in android/app/build.gradle.:
      compile project(':react-native-play-services')

API

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 execute goToSettings().
      • If onGmsNeedUpdate is not specified, it will execute goToMarket().
    • 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.

About

Google Play Services API for React Native.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 81.7%
  • JavaScript 18.3%