@react-native-firebase/messaging 14.9.4 → 14.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [14.10.0](https://github.com/invertase/react-native-firebase/compare/v14.9.4...v14.10.0) (2022-05-26)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **messaging, getToken:** add options for messaging instance ([88e218e](https://github.com/invertase/react-native-firebase/commit/88e218e7c5c9459197e4469c02de9efadcc14568))
11
+
6
12
  ## [14.9.4](https://github.com/invertase/react-native-firebase/compare/v14.9.3...v14.9.4) (2022-05-14)
7
13
 
8
14
  **Note:** Version bump only for package @react-native-firebase/messaging
@@ -29,6 +29,7 @@ import com.facebook.react.bridge.ReadableMap;
29
29
  import com.facebook.react.bridge.WritableMap;
30
30
  import com.facebook.react.bridge.WritableNativeMap;
31
31
  import com.google.android.gms.tasks.Tasks;
32
+ import com.google.firebase.FirebaseApp;
32
33
  import com.google.firebase.messaging.FirebaseMessaging;
33
34
  import com.google.firebase.messaging.RemoteMessage;
34
35
  import io.invertase.firebase.common.ReactNativeFirebaseEventEmitter;
@@ -120,8 +121,9 @@ public class ReactNativeFirebaseMessagingModule extends ReactNativeFirebaseModul
120
121
  }
121
122
 
122
123
  @ReactMethod
123
- public void getToken(Promise promise) {
124
- Tasks.call(getExecutor(), () -> Tasks.await(FirebaseMessaging.getInstance().getToken()))
124
+ public void getToken(String appName, String senderId, Promise promise) {
125
+ FirebaseMessaging messagingInstance = FirebaseApp.getInstance(appName).get(FirebaseMessaging.class);
126
+ Tasks.call(getExecutor(), () -> Tasks.await(messagingInstance.getToken()))
125
127
  .addOnCompleteListener(
126
128
  task -> {
127
129
  if (task.isSuccessful()) {
@@ -133,11 +135,12 @@ public class ReactNativeFirebaseMessagingModule extends ReactNativeFirebaseModul
133
135
  }
134
136
 
135
137
  @ReactMethod
136
- public void deleteToken(Promise promise) {
138
+ public void deleteToken(String appName, String senderId, Promise promise) {
139
+ FirebaseMessaging messagingInstance = FirebaseApp.getInstance(appName).get(FirebaseMessaging.class);
137
140
  Tasks.call(
138
141
  getExecutor(),
139
142
  () -> {
140
- Tasks.await(FirebaseMessaging.getInstance().deleteToken());
143
+ Tasks.await(messagingInstance.deleteToken());
141
144
  return null;
142
145
  })
143
146
  .addOnCompleteListener(
@@ -107,7 +107,11 @@ RCT_EXPORT_METHOD(signalBackgroundMessageHandlerSet) {
107
107
  }
108
108
  }
109
109
 
110
- RCT_EXPORT_METHOD(getToken : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
110
+ RCT_EXPORT_METHOD(getToken
111
+ : (NSString *)appName
112
+ : (NSString *)senderId
113
+ : (RCTPromiseResolveBlock)resolve
114
+ : (RCTPromiseRejectBlock)reject) {
111
115
  #if !(TARGET_IPHONE_SIMULATOR)
112
116
  if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == NO) {
113
117
  [RNFBSharedUtils
@@ -123,23 +127,30 @@ RCT_EXPORT_METHOD(getToken : (RCTPromiseResolveBlock)resolve : (RCTPromiseReject
123
127
  #endif
124
128
 
125
129
  [[FIRMessaging messaging]
126
- tokenWithCompletion:^(NSString *_Nullable token, NSError *_Nullable error) {
127
- if (error) {
128
- [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
129
- } else {
130
- resolve(token);
131
- }
132
- }];
130
+ retrieveFCMTokenForSenderID:senderId
131
+ completion:^(NSString *_Nullable token, NSError *_Nullable error) {
132
+ if (error) {
133
+ [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
134
+ } else {
135
+ resolve(token);
136
+ }
137
+ }];
133
138
  }
134
139
 
135
- RCT_EXPORT_METHOD(deleteToken : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
136
- [[FIRMessaging messaging] deleteTokenWithCompletion:^(NSError *_Nullable error) {
137
- if (error) {
138
- [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
139
- } else {
140
- resolve([NSNull null]);
141
- }
142
- }];
140
+ RCT_EXPORT_METHOD(deleteToken
141
+ : (NSString *)appName
142
+ : (NSString *)senderId
143
+ : (RCTPromiseResolveBlock)resolve
144
+ : (RCTPromiseRejectBlock)reject) {
145
+ [[FIRMessaging messaging] deleteFCMTokenForSenderID:senderId
146
+ completion:^(NSError *_Nullable error) {
147
+ if (error) {
148
+ [RNFBSharedUtils rejectPromiseWithNSError:reject
149
+ error:error];
150
+ } else {
151
+ resolve([NSNull null]);
152
+ }
153
+ }];
143
154
  }
144
155
 
145
156
  RCT_EXPORT_METHOD(getAPNSToken : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
package/lib/index.d.ts CHANGED
@@ -143,6 +143,25 @@ export namespace FirebaseMessagingTypes {
143
143
  threadId?: string;
144
144
  }
145
145
 
146
+ /**
147
+ * Options for `getToken()`, `deleteToken()`
148
+ */
149
+ export interface TokenOptions {
150
+ /**
151
+ * The app name of the FirebaseApp instance.
152
+ *
153
+ * @platform android Android
154
+ */
155
+ appName?: string;
156
+
157
+ /**
158
+ * The senderID for a particular Firebase project.
159
+ *
160
+ * @platform ios iOS
161
+ */
162
+ senderId?: string;
163
+ }
164
+
146
165
  export interface Notification {
147
166
  /**
148
167
  * The notification title.
@@ -579,8 +598,7 @@ export namespace FirebaseMessagingTypes {
579
598
  getDidOpenSettingsForNotification(): Promise<boolean>;
580
599
 
581
600
  /**
582
- * Returns an FCM token for this device. Optionally you can specify a custom authorized entity
583
- * or scope to tailor tokens to your own use-case.
601
+ * Returns an FCM token for this device. Optionally you can specify a custom options to your own use-case.
584
602
  *
585
603
  * It is recommended you call this method on app start and update your backend with the new token.
586
604
  *
@@ -602,8 +620,10 @@ export namespace FirebaseMessagingTypes {
602
620
  * fcmTokens: firebase.firestore.FieldValues.arrayUnion(fcmToken),
603
621
  * });
604
622
  * ```
623
+ *
624
+ * @param options Options to override senderId (iOS) and projectId (Android).
605
625
  */
606
- getToken(): Promise<string>;
626
+ getToken(options?: TokenOptions): Promise<string>;
607
627
 
608
628
  /**
609
629
  * Returns wether the root view is headless or not
@@ -623,8 +643,10 @@ export namespace FirebaseMessagingTypes {
623
643
  * ```js
624
644
  * await firebase.messaging().deleteToken();
625
645
  * ```
646
+ *
647
+ * @param options Options to override senderId (iOS) and projectId (Android).
626
648
  */
627
- deleteToken(): Promise<void>;
649
+ deleteToken(options?: TokenOptions): Promise<void>;
628
650
 
629
651
  /**
630
652
  * When any FCM payload is received, the listener callback is called with a `RemoteMessage`.
package/lib/index.js CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  isIOS,
24
24
  isObject,
25
25
  isString,
26
+ isUndefined,
26
27
  } from '@react-native-firebase/app/lib/common';
27
28
  import {
28
29
  createModuleNamespace,
@@ -154,12 +155,34 @@ class FirebaseMessagingModule extends FirebaseModule {
154
155
  return this.native.getIsHeadless();
155
156
  }
156
157
 
157
- getToken() {
158
- return this.native.getToken();
158
+ getToken({ appName, senderId } = {}) {
159
+ if (!isUndefined(appName) && !isString(appName)) {
160
+ throw new Error("firebase.messaging().getToken(*) 'projectId' expected a string.");
161
+ }
162
+
163
+ if (!isUndefined(senderId) && !isString(senderId)) {
164
+ throw new Error("firebase.messaging().getToken(*) 'senderId' expected a string.");
165
+ }
166
+
167
+ return this.native.getToken(
168
+ appName || this.app.name,
169
+ senderId || this.app.options.messagingSenderId,
170
+ );
159
171
  }
160
172
 
161
- deleteToken() {
162
- return this.native.deleteToken();
173
+ deleteToken({ appName, senderId } = {}) {
174
+ if (!isUndefined(appName) && !isString(appName)) {
175
+ throw new Error("firebase.messaging().deleteToken(*) 'projectId' expected a string.");
176
+ }
177
+
178
+ if (!isUndefined(senderId) && !isString(senderId)) {
179
+ throw new Error("firebase.messaging().deleteToken(*) 'senderId' expected a string.");
180
+ }
181
+
182
+ return this.native.deleteToken(
183
+ appName || this.app.name,
184
+ senderId || this.app.options.messagingSenderId,
185
+ );
163
186
  }
164
187
 
165
188
  onMessage(listener) {
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '14.9.4';
2
+ module.exports = '14.10.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/messaging",
3
- "version": "14.9.4",
3
+ "version": "14.10.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - React Native Firebase provides native integration of Firebase Cloud Messaging (FCM) for both Android & iOS. FCM is a cost free service, allowing for server-device and device-device communication. The React Native Firebase Messaging module provides a simple JavaScript API to interact with FCM.",
6
6
  "main": "lib/index.js",
@@ -22,10 +22,10 @@
22
22
  "messaging"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@react-native-firebase/app": "14.9.4"
25
+ "@react-native-firebase/app": "14.10.0"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "42f6d96313cb193ae7918c72622c6a75e945570a"
30
+ "gitHead": "ecdaef03c666313272e0b9debf86d05498d539dc"
31
31
  }