[js][android] Use GoogleApiAvailability to prompt the user to install Google Play Services if it is not installed

This commit is contained in:
Chris Bianca
2017-04-10 09:50:42 +01:00
parent 90546aa7dd
commit baa198ea7d
2 changed files with 27 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ export default class Firebase {
constructor(options: Object = {}) {
this.eventHandlers = {};
this.debug = options.debug || false;
this.options = Object.assign({ errorOnMissingPlayServices: true }, options);
this.options = Object.assign({ errorOnMissingPlayServices: true, promptOnMissingPlayServices: true }, options);
if (this.debug) {
Log.enable(this.debug);
@@ -62,8 +62,17 @@ export default class Firebase {
this._log = new Log('firebase');
if (this.options.errorOnMissingPlayServices && !this.googleApiAvailability.isAvailable) {
throw new Error(`Google Play Services is required to run this application but no valid installation was found (Code ${this.googleApiAvailability.status}).`);
if (!this.googleApiAvailability.isAvailable) {
if (this.options.promptOnMissingPlayServices && this.googleApiAvailability.isUserResolvableError) {
FirebaseModule.promptPlayServices();
} else {
const error = `Google Play Services is required to run this application but no valid installation was found (Code ${this.googleApiAvailability.status}).`;
if (this.options.errorOnMissingPlayServices) {
throw new Error(error);
} else {
console.warn(error);
}
}
}
this.auth = this._staticsOrInstance('auth', AuthStatics, Auth);