Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

feat: add method to get fcm token #2369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ public void unsubscribeFromTopic(String topic) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
}


@ReactMethod
public void getFCMToken(final Promise promise) {
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(task -> {
if (!task.isSuccessful()) {
Log.e(LOG_TAG, "exception", task.getException());
promise.reject(task.getException());
} else {
promise.resolve(task.getResult());
}
});
}

@ReactMethod
public void presentLocalNotification(ReadableMap details) {
Bundle bundle = Arguments.toBundle(details);
Expand Down
12 changes: 12 additions & 0 deletions component/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ NotificationsComponent.prototype.unsubscribeFromTopic = function(topic) {
RNPushNotification.unsubscribeFromTopic(topic);
};

NotificationsComponent.prototype.getFCMToken = function() {
return new Promise(function(resolve, reject) {
RNPushNotification.getFCMToken()
.then(function(token) {
resolve(token);
})
.catch(function(err) {
reject(err);
});
});
};

NotificationsComponent.prototype.cancelLocalNotification = function(details) {
RNPushNotification.cancelLocalNotification(details);
};
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ Notifications.unsubscribeFromTopic = function () {
return this.callNative('unsubscribeFromTopic', arguments);
};

Notifications.getFCMToken = function () {
return this.callNative('getFCMToken', arguments);
};

Notifications.presentLocalNotification = function() {
return this.callNative('presentLocalNotification', arguments);
};
Expand Down