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

Commit caeaa7d

Browse files
When Google Play Services is not available, show a dialog asking the user to install it #609
1 parent 1484dd8 commit caeaa7d

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
### New
1010

1111
- [#170](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/170) Need a way to unregister push notification from Firebase
12+
- [#609](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/609) When Google Play Services is not available, show a dialog asking the user to install it
13+
1214

1315
### Fixes
1416
- [#601](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/601) Error using admob

src/firebase.android.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,20 @@ firebase.getRemoteConfigDefaults = properties => {
486486
};
487487

488488
firebase._isGooglePlayServicesAvailable = () => {
489-
const context = com.tns.NativeScriptApplication.getInstance();
489+
const activity = appModule.android.foregroundActivity || appModule.android.startActivity;
490+
const googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
490491
const playServiceStatusSuccess = com.google.android.gms.common.ConnectionResult.SUCCESS; // 0
491-
const playServicesStatus = com.google.android.gms.common.GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
492-
return playServicesStatus === playServiceStatusSuccess;
492+
const playServicesStatus = googleApiAvailability.isGooglePlayServicesAvailable(activity);
493+
const available = playServicesStatus === playServiceStatusSuccess;
494+
if (!available && googleApiAvailability.isUserResolvableError(playServicesStatus)) {
495+
// show a dialog offering the user to update (no need to wait for it to finish)
496+
googleApiAvailability.showErrorDialogFragment(activity, playServicesStatus, 1, new android.content.DialogInterface.OnCancelListener({
497+
onCancel: dialogInterface => {
498+
console.log("Canceled");
499+
}
500+
}));
501+
}
502+
return available;
493503
};
494504

495505
firebase.analytics.logEvent = arg => {

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "5.1.2",
3+
"version": "5.1.3",
44
"description": "Fire. Base. Firebase!",
55
"main": "firebase",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)