From fd6d25f7df5bbe638758ebbddfd92ed7987b5b1b Mon Sep 17 00:00:00 2001 From: Yoav Luft Date: Tue, 23 Nov 2021 15:39:27 +0100 Subject: [PATCH] Update package to use firebase-messaging 23.0.0 --- android/build.gradle | 29 ++++++++++++++++--- .../ReactNativeNotificationHubModule.java | 1 - .../ReactNativeRegistrationIntentService.java | 19 +++++++----- package.json | 6 ++-- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index f7ff4b8e..a8836837 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,13 +1,24 @@ apply plugin: 'com.android.library' +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath('com.android.tools.build:gradle:4.1.3') + classpath 'com.google.gms:google-services:4.3.10' // Google Services plugin + } +} + android { compileSdkVersion 28 defaultConfig { - minSdkVersion 16 + minSdkVersion 26 targetSdkVersion 28 versionCode 1 - versionName "1.0" + versionName "1.1" ndk { abiFilters "armeabi-v7a", "x86" } @@ -23,8 +34,17 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation 'com.facebook.react:react-native:+' - implementation 'com.google.firebase:firebase-messaging:17.6.0' - implementation 'com.android.support:appcompat-v7:28.0.0' + + implementation platform('com.google.firebase:firebase-bom:29.0.0') + + // Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries + // When using the BoM, you don't specify versions in Firebase library dependencies + implementation 'com.google.firebase:firebase-messaging' + implementation 'com.google.firebase:firebase-analytics' + + implementation 'com.google.android.gms:play-services-base:17.6.0' + + implementation 'com.android.support:appcompat-v7:28.+' implementation 'com.microsoft.azure:notification-hubs-android-sdk:0.6@aar' } @@ -32,5 +52,6 @@ repositories { maven { url "http://dl.bintray.com/microsoftazuremobile/SDK" } + mavenCentral() } diff --git a/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeNotificationHubModule.java b/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeNotificationHubModule.java index 7c43beb1..c0f30071 100644 --- a/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeNotificationHubModule.java +++ b/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeNotificationHubModule.java @@ -402,7 +402,6 @@ public void onHostPause() { public void onHostDestroy() { } - @Override public void onNewIntent(Intent intent) { Bundle bundle = ReactNativeUtil.getBundleFromIntent(intent); if (bundle != null) { diff --git a/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeRegistrationIntentService.java b/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeRegistrationIntentService.java index 4c94d275..f1d0eaa4 100644 --- a/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeRegistrationIntentService.java +++ b/android/src/main/java/com/azure/reactnative/notificationhub/ReactNativeRegistrationIntentService.java @@ -3,13 +3,14 @@ import android.content.Context; import android.content.Intent; +import androidx.annotation.NonNull; import androidx.core.app.JobIntentService; import android.util.Log; -import com.google.android.gms.tasks.OnSuccessListener; -import com.google.firebase.iid.FirebaseInstanceId; -import com.google.firebase.iid.InstanceIdResult; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.messaging.FirebaseMessaging; import com.microsoft.windowsazure.messaging.NotificationHub; import java.util.concurrent.ExecutorService; @@ -49,13 +50,17 @@ protected void onHandleWork(Intent intent) { return; } - FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( - mPool, new OnSuccessListener() { + FirebaseMessaging.getInstance().getToken().addOnCompleteListener( + mPool, new OnCompleteListener() { @Override - public void onSuccess(InstanceIdResult instanceIdResult) { + public void onComplete(@NonNull Task task) { + if (!task.isSuccessful()) { + Log.w(TAG, "Fetching FCM registration token failed.", task.getException()); + return; + } try { String regID = notificationHubUtil.getRegistrationID(ReactNativeRegistrationIntentService.this); - String token = instanceIdResult.getToken(); + String token = task.getResult(); Log.d(TAG, "FCM Registration Token: " + token); // Storing the registration ID indicates whether the generated token has been diff --git a/package.json b/package.json index 43425f34..4b04f18c 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ }, "homepage": "https://github.com/CatalystCode/react-native-azurenotificationhub#readme", "devDependencies": { - "react": "^15.3.0", - "react-native": "^0.32.0", - "react-native-windows": "^0.32.0" + "react": "17.0.1", + "react-native": "~0.64.3", + "react-native-windows": "~0.64.26" } }