|
7 | 7 | import com.facebook.react.ReactApplication;
|
8 | 8 | import com.facebook.react.ReactInstanceManager;
|
9 | 9 | import com.facebook.react.bridge.ReactContext;
|
10 |
| -import com.facebook.react.modules.core.DeviceEventManagerModule; |
11 |
| -import com.google.android.gms.tasks.OnSuccessListener; |
12 |
| -import com.google.firebase.iid.FirebaseInstanceId; |
13 |
| -import com.google.firebase.iid.InstanceIdResult; |
| 10 | +import com.google.firebase.messaging.FirebaseMessaging; |
14 | 11 | import com.wix.reactnativenotifications.BuildConfig;
|
15 | 12 | import com.wix.reactnativenotifications.core.JsIOHelper;
|
16 | 13 |
|
@@ -75,17 +72,19 @@ public void onAppReady() {
|
75 | 72 | }
|
76 | 73 |
|
77 | 74 | protected void refreshToken() {
|
78 |
| - FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() { |
79 |
| - @Override |
80 |
| - public void onSuccess(InstanceIdResult instanceIdResult) { |
81 |
| - sToken = instanceIdResult.getToken(); |
| 75 | + FirebaseMessaging.getInstance().getToken() |
| 76 | + .addOnCompleteListener(task -> { |
| 77 | + if (!task.isSuccessful()) { |
| 78 | + if (BuildConfig.DEBUG) Log.w(LOGTAG, "Fetching FCM registration token failed", task.getException()); |
| 79 | + return; |
| 80 | + } |
| 81 | + sToken = task.getResult(); |
82 | 82 | if (mAppContext instanceof IFcmTokenListenerApplication) {
|
83 | 83 | ((IFcmTokenListenerApplication) mAppContext).onNewFCMToken(sToken);
|
84 | 84 | }
|
85 | 85 | if (BuildConfig.DEBUG) Log.i(LOGTAG, "FCM has a new token" + "=" + sToken);
|
86 | 86 | sendTokenToJS();
|
87 |
| - } |
88 |
| - }); |
| 87 | + }); |
89 | 88 | }
|
90 | 89 |
|
91 | 90 | protected void sendTokenToJS() {
|
|
0 commit comments