@react-native-firebase/messaging 23.7.0 → 23.8.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.
Files changed (109) hide show
  1. package/dist/commonjs/index.js +61 -0
  2. package/dist/commonjs/index.js.map +1 -0
  3. package/dist/commonjs/modular.js +439 -0
  4. package/dist/commonjs/modular.js.map +1 -0
  5. package/dist/commonjs/namespaced.js +407 -0
  6. package/dist/commonjs/namespaced.js.map +1 -0
  7. package/dist/commonjs/package.json +1 -0
  8. package/dist/commonjs/remoteMessageOptions.js +87 -0
  9. package/dist/commonjs/remoteMessageOptions.js.map +1 -0
  10. package/dist/commonjs/statics.js +29 -0
  11. package/dist/commonjs/statics.js.map +1 -0
  12. package/dist/commonjs/types/messaging.js +105 -0
  13. package/dist/commonjs/types/messaging.js.map +1 -0
  14. package/dist/commonjs/version.js +9 -0
  15. package/dist/commonjs/version.js.map +1 -0
  16. package/{ios/RNFBMessaging/RNFBMessaging+FIRMessagingDelegate.h → dist/module/index.js} +11 -12
  17. package/dist/module/index.js.map +1 -0
  18. package/{lib/modular/index.js → dist/module/modular.js} +135 -119
  19. package/dist/module/modular.js.map +1 -0
  20. package/{lib/index.js → dist/module/namespaced.js} +70 -193
  21. package/dist/module/namespaced.js.map +1 -0
  22. package/dist/module/package.json +1 -0
  23. package/{lib → dist/module}/remoteMessageOptions.js +10 -27
  24. package/dist/module/remoteMessageOptions.js.map +1 -0
  25. package/dist/module/statics.js +25 -0
  26. package/dist/module/statics.js.map +1 -0
  27. package/dist/module/types/messaging.js +124 -0
  28. package/dist/module/types/messaging.js.map +1 -0
  29. package/dist/module/version.js +5 -0
  30. package/dist/module/version.js.map +1 -0
  31. package/dist/typescript/commonjs/lib/index.d.ts +6 -0
  32. package/dist/typescript/commonjs/lib/index.d.ts.map +1 -0
  33. package/{lib/modular/index.d.ts → dist/typescript/commonjs/lib/modular.d.ts} +86 -164
  34. package/dist/typescript/commonjs/lib/modular.d.ts.map +1 -0
  35. package/dist/typescript/commonjs/lib/namespaced.d.ts +12 -0
  36. package/dist/typescript/commonjs/lib/namespaced.d.ts.map +1 -0
  37. package/dist/typescript/commonjs/lib/remoteMessageOptions.d.ts +14 -0
  38. package/dist/typescript/commonjs/lib/remoteMessageOptions.d.ts.map +1 -0
  39. package/dist/typescript/commonjs/lib/statics.d.ts +20 -0
  40. package/dist/typescript/commonjs/lib/statics.d.ts.map +1 -0
  41. package/dist/typescript/commonjs/lib/types/messaging.d.ts +673 -0
  42. package/dist/typescript/commonjs/lib/types/messaging.d.ts.map +1 -0
  43. package/dist/typescript/commonjs/lib/version.d.ts +2 -0
  44. package/dist/typescript/commonjs/lib/version.d.ts.map +1 -0
  45. package/dist/typescript/commonjs/package.json +1 -0
  46. package/dist/typescript/module/lib/index.d.ts +6 -0
  47. package/dist/typescript/module/lib/index.d.ts.map +1 -0
  48. package/dist/typescript/module/lib/modular.d.ts +247 -0
  49. package/dist/typescript/module/lib/modular.d.ts.map +1 -0
  50. package/dist/typescript/module/lib/namespaced.d.ts +12 -0
  51. package/dist/typescript/module/lib/namespaced.d.ts.map +1 -0
  52. package/dist/typescript/module/lib/remoteMessageOptions.d.ts +14 -0
  53. package/dist/typescript/module/lib/remoteMessageOptions.d.ts.map +1 -0
  54. package/dist/typescript/module/lib/statics.d.ts +20 -0
  55. package/dist/typescript/module/lib/statics.d.ts.map +1 -0
  56. package/dist/typescript/module/lib/types/messaging.d.ts +673 -0
  57. package/dist/typescript/module/lib/types/messaging.d.ts.map +1 -0
  58. package/dist/typescript/module/lib/version.d.ts +2 -0
  59. package/dist/typescript/module/lib/version.d.ts.map +1 -0
  60. package/dist/typescript/module/package.json +1 -0
  61. package/{ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.h → lib/index.ts} +28 -21
  62. package/lib/modular.ts +447 -0
  63. package/lib/namespaced.ts +583 -0
  64. package/lib/remoteMessageOptions.ts +110 -0
  65. package/lib/{statics.js → statics.ts} +6 -3
  66. package/lib/types/messaging.ts +815 -0
  67. package/lib/version.ts +2 -0
  68. package/package.json +64 -8
  69. package/tsconfig.json +21 -0
  70. package/CHANGELOG.md +0 -1181
  71. package/RNFBMessaging.podspec +0 -50
  72. package/android/.editorconfig +0 -10
  73. package/android/build.gradle +0 -149
  74. package/android/lint.xml +0 -5
  75. package/android/settings.gradle +0 -1
  76. package/android/src/main/AndroidManifest.xml +0 -43
  77. package/android/src/main/java/io/invertase/firebase/messaging/JsonConvert.java +0 -127
  78. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingHeadlessService.java +0 -30
  79. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java +0 -332
  80. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingPackage.java +0 -41
  81. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingReceiver.java +0 -66
  82. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingSerializer.java +0 -225
  83. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingService.java +0 -37
  84. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingStore.java +0 -15
  85. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingStoreHelper.java +0 -23
  86. package/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingStoreImpl.java +0 -97
  87. package/android/src/main/res/values/colors.xml +0 -143
  88. package/app.plugin.js +0 -1
  89. package/ios/RNFBMessaging/RNFBMessaging+AppDelegate.h +0 -54
  90. package/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m +0 -251
  91. package/ios/RNFBMessaging/RNFBMessaging+FIRMessagingDelegate.m +0 -70
  92. package/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.h +0 -29
  93. package/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m +0 -173
  94. package/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m +0 -185
  95. package/ios/RNFBMessaging/RNFBMessagingModule.h +0 -26
  96. package/ios/RNFBMessaging/RNFBMessagingModule.m +0 -431
  97. package/ios/RNFBMessaging/RNFBMessagingSerializer.h +0 -32
  98. package/ios/RNFBMessaging/RNFBMessagingSerializer.m +0 -235
  99. package/ios/RNFBMessaging.xcodeproj/project.pbxproj +0 -384
  100. package/ios/RNFBMessaging.xcodeproj/xcshareddata/IDETemplateMacros.plist +0 -24
  101. package/lib/index.d.ts +0 -1233
  102. package/lib/version.js +0 -2
  103. package/plugin/build/android/index.d.ts +0 -2
  104. package/plugin/build/android/index.js +0 -5
  105. package/plugin/build/android/setupFirebaseNotifationIcon.d.ts +0 -8
  106. package/plugin/build/android/setupFirebaseNotifationIcon.js +0 -62
  107. package/plugin/build/index.d.ts +0 -3
  108. package/plugin/build/index.js +0 -16
  109. package/plugin/tsconfig.tsbuildinfo +0 -1
@@ -1,431 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import <Firebase/Firebase.h>
19
- #import <RNFBApp/RNFBSharedUtils.h>
20
- #import <React/RCTConvert.h>
21
- #import <React/RCTUtils.h>
22
-
23
- #import "RNFBMessaging+AppDelegate.h"
24
- #import "RNFBMessaging+NSNotificationCenter.h"
25
- #import "RNFBMessaging+UNUserNotificationCenter.h"
26
- #import "RNFBMessagingModule.h"
27
- #import "RNFBMessagingSerializer.h"
28
-
29
- @implementation RNFBMessagingModule
30
- #pragma mark -
31
- #pragma mark Module Setup
32
-
33
- RCT_EXPORT_MODULE();
34
-
35
- - (id)init {
36
- self = [super init];
37
- return self;
38
- }
39
-
40
- - (dispatch_queue_t)methodQueue {
41
- return dispatch_get_main_queue();
42
- }
43
-
44
- + (BOOL)requiresMainQueueSetup {
45
- return YES;
46
- }
47
-
48
- + (NSDictionary *)addCustomPropsToUserProps:(NSDictionary *_Nullable)userProps
49
- withLaunchOptions:(NSDictionary *_Nullable)launchOptions {
50
- NSMutableDictionary *appProperties =
51
- userProps != nil ? [userProps mutableCopy] : [NSMutableDictionary dictionary];
52
- appProperties[@"isHeadless"] = @([RCTConvert BOOL:@(NO)]);
53
-
54
- if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
55
- if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
56
- appProperties[@"isHeadless"] = @([RCTConvert BOOL:@(YES)]);
57
- }
58
- }
59
-
60
- return [NSDictionary dictionaryWithDictionary:appProperties];
61
- }
62
-
63
- - (NSDictionary *)constantsToExport {
64
- NSMutableDictionary *constants = [NSMutableDictionary new];
65
- constants[@"isAutoInitEnabled"] =
66
- @([RCTConvert BOOL:@([FIRMessaging messaging].autoInitEnabled)]);
67
- constants[@"isRegisteredForRemoteNotifications"] = @(
68
- [RCTConvert BOOL:@([[UIApplication sharedApplication] isRegisteredForRemoteNotifications])]);
69
- constants[@"isDeliveryMetricsExportToBigQueryEnabled"] =
70
- @([RCTConvert BOOL:@(_isDeliveryMetricsExportToBigQueryEnabled)]);
71
- return constants;
72
- }
73
-
74
- #pragma mark -
75
- #pragma mark Firebase Messaging Methods
76
-
77
- RCT_EXPORT_METHOD(getInitialNotification
78
- : (RCTPromiseResolveBlock)resolve
79
- : (RCTPromiseRejectBlock)reject) {
80
- resolve([[RNFBMessagingUNUserNotificationCenter sharedInstance] getInitialNotification]);
81
- }
82
-
83
- RCT_EXPORT_METHOD(getDidOpenSettingsForNotification
84
- : (RCTPromiseResolveBlock)resolve
85
- : (RCTPromiseRejectBlock)reject) {
86
- resolve(
87
- [[RNFBMessagingUNUserNotificationCenter sharedInstance] getDidOpenSettingsForNotification]);
88
- }
89
-
90
- RCT_EXPORT_METHOD(setAutoInitEnabled
91
- : (BOOL)enabled
92
- : (RCTPromiseResolveBlock)resolve
93
- : (RCTPromiseRejectBlock)reject) {
94
- @try {
95
- [FIRMessaging messaging].autoInitEnabled = enabled;
96
- } @catch (NSException *exception) {
97
- return [RNFBSharedUtils rejectPromiseWithExceptionDict:reject exception:exception];
98
- }
99
-
100
- return resolve([NSNull null]);
101
- }
102
-
103
- RCT_EXPORT_METHOD(signalBackgroundMessageHandlerSet) {
104
- DLog(@"signalBackgroundMessageHandlerSet called");
105
- @try {
106
- [[RNFBMessagingAppDelegate sharedInstance] signalBackgroundMessageHandlerSet];
107
- } @catch (NSException *exception) {
108
- ELog(@"signalBackgroundMessageHandlerSet failed");
109
- }
110
- }
111
-
112
- RCT_EXPORT_METHOD(getToken
113
- : (NSString *)appName
114
- : (NSString *)senderId
115
- : (RCTPromiseResolveBlock)resolve
116
- : (RCTPromiseRejectBlock)reject) {
117
- if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == NO) {
118
- [RNFBSharedUtils
119
- rejectPromiseWithUserInfo:reject
120
- userInfo:(NSMutableDictionary *)@{
121
- @"code" : @"unregistered",
122
- @"message" :
123
- @"You must be registered for remote messages before calling "
124
- @"getToken, see messaging().registerDeviceForRemoteMessages().",
125
- }];
126
- return;
127
- }
128
-
129
- // As of firebase-ios-sdk 10.4.0, an APNS token is strictly required for getToken to work
130
- NSData *apnsToken = [FIRMessaging messaging].APNSToken;
131
- if (apnsToken == nil) {
132
- DLog(@"RNFBMessaging getToken - no APNS token is available. Firebase requires an APNS token to "
133
- @"vend an FCM token in firebase-ios-sdk 10.4.0 and higher. See documentation on "
134
- @"setAPNSToken and getAPNSToken.")
135
- }
136
-
137
- [[FIRMessaging messaging]
138
- retrieveFCMTokenForSenderID:senderId
139
- completion:^(NSString *_Nullable token, NSError *_Nullable error) {
140
- if (error) {
141
- [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
142
- } else {
143
- resolve(token);
144
- }
145
- }];
146
- }
147
-
148
- RCT_EXPORT_METHOD(deleteToken
149
- : (NSString *)appName
150
- : (NSString *)senderId
151
- : (RCTPromiseResolveBlock)resolve
152
- : (RCTPromiseRejectBlock)reject) {
153
- [[FIRMessaging messaging] deleteFCMTokenForSenderID:senderId
154
- completion:^(NSError *_Nullable error) {
155
- if (error) {
156
- [RNFBSharedUtils rejectPromiseWithNSError:reject
157
- error:error];
158
- } else {
159
- resolve([NSNull null]);
160
- }
161
- }];
162
- }
163
-
164
- RCT_EXPORT_METHOD(getAPNSToken : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
165
- NSData *apnsToken = [FIRMessaging messaging].APNSToken;
166
- if (apnsToken) {
167
- resolve([RNFBMessagingSerializer APNSTokenFromNSData:apnsToken]);
168
- } else {
169
- #if TARGET_IPHONE_SIMULATOR
170
- #if !TARGET_CPU_ARM64
171
- DLog(@"RNFBMessaging getAPNSToken - Simulator without APNS support detected, with no token "
172
- @"set. Use setAPNSToken with an arbitrary string if needed for testing.")
173
- resolve([NSNull null]);
174
- return;
175
- #endif
176
- DLog(@"RNFBMessaging getAPNSToken - ARM64 Simulator detected, but no APNS token available. "
177
- @"APNS token may be possible. macOS13+ / iOS16+ / M1 mac required for assumption to be "
178
- @"valid. "
179
- @"Use setAPNSToken in testing if needed.");
180
- #endif
181
- if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == NO) {
182
- [RNFBSharedUtils
183
- rejectPromiseWithUserInfo:reject
184
- userInfo:(NSMutableDictionary *)@{
185
- @"code" : @"unregistered",
186
- @"message" : @"You must be registered for remote messages before "
187
- @"calling getAPNSToken, see "
188
- @"messaging().registerDeviceForRemoteMessages().",
189
- }];
190
- return;
191
- }
192
- resolve([NSNull null]);
193
- }
194
- }
195
-
196
- RCT_EXPORT_METHOD(setAPNSToken
197
- : (NSString *)token
198
- : (NSString *)type
199
- : (RCTPromiseResolveBlock)resolve
200
- : (RCTPromiseRejectBlock)reject) {
201
- // Default to unknown (determined by provisioning profile) type, but user may have passed type as
202
- // param
203
- FIRMessagingAPNSTokenType tokenType = FIRMessagingAPNSTokenTypeUnknown;
204
- if (type != nil && [@"prod" isEqualToString:type]) {
205
- tokenType = FIRMessagingAPNSTokenTypeProd;
206
- } else if (type != nil && [@"sandbox" isEqualToString:type]) {
207
- tokenType = FIRMessagingAPNSTokenTypeSandbox;
208
- }
209
-
210
- [[FIRMessaging messaging] setAPNSToken:[RNFBMessagingSerializer APNSTokenDataFromNSString:token]
211
- type:tokenType];
212
- resolve([NSNull null]);
213
- }
214
-
215
- RCT_EXPORT_METHOD(getIsHeadless : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
216
- RNFBMessagingNSNotificationCenter *notifCenter =
217
- [RNFBMessagingNSNotificationCenter sharedInstance];
218
-
219
- return resolve(@([RCTConvert BOOL:@(notifCenter.isHeadless)]));
220
- }
221
-
222
- RCT_EXPORT_METHOD(completeNotificationProcessing) {
223
- dispatch_get_main_queue(), ^{
224
- RNFBMessagingAppDelegate *appDelegate = [RNFBMessagingAppDelegate sharedInstance];
225
- if (appDelegate.completionHandler) {
226
- appDelegate.completionHandler(UIBackgroundFetchResultNewData);
227
- appDelegate.completionHandler = nil;
228
- }
229
- if (appDelegate.backgroundTaskId != UIBackgroundTaskInvalid) {
230
- [[UIApplication sharedApplication] endBackgroundTask:appDelegate.backgroundTaskId];
231
- appDelegate.backgroundTaskId = UIBackgroundTaskInvalid;
232
- }
233
- };
234
- }
235
-
236
- RCT_EXPORT_METHOD(requestPermission
237
- : (NSDictionary *)permissions
238
- : (RCTPromiseResolveBlock)resolve
239
- : (RCTPromiseRejectBlock)reject) {
240
- if (RCTRunningInAppExtension()) {
241
- [RNFBSharedUtils
242
- rejectPromiseWithUserInfo:reject
243
- userInfo:[@{
244
- @"code" : @"unavailable-in-extension",
245
- @"message" : @"requestPermission can not be called in App Extensions"
246
- } mutableCopy]];
247
- return;
248
- }
249
-
250
- UNAuthorizationOptions options = UNAuthorizationOptionNone;
251
-
252
- if ([permissions[@"alert"] isEqual:@(YES)]) {
253
- options |= UNAuthorizationOptionAlert;
254
- }
255
-
256
- if ([permissions[@"badge"] isEqual:@(YES)]) {
257
- options |= UNAuthorizationOptionBadge;
258
- }
259
-
260
- if ([permissions[@"sound"] isEqual:@(YES)]) {
261
- options |= UNAuthorizationOptionSound;
262
- }
263
-
264
- if ([permissions[@"criticalAlert"] isEqual:@(YES)]) {
265
- options |= UNAuthorizationOptionCriticalAlert;
266
- }
267
-
268
- if ([permissions[@"provisional"] isEqual:@(YES)]) {
269
- options |= UNAuthorizationOptionProvisional;
270
- }
271
-
272
- if ([permissions[@"announcement"] isEqual:@(YES)]) {
273
- options |= UNAuthorizationOptionAnnouncement;
274
- }
275
-
276
- if ([permissions[@"carPlay"] isEqual:@(YES)]) {
277
- options |= UNAuthorizationOptionCarPlay;
278
- }
279
-
280
- if ([permissions[@"providesAppNotificationSettings"] isEqual:@(YES)]) {
281
- options |= UNAuthorizationOptionProvidesAppNotificationSettings;
282
- }
283
-
284
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
285
- [center requestAuthorizationWithOptions:options
286
- completionHandler:^(BOOL granted, NSError *_Nullable error) {
287
- if (error) {
288
- [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
289
- } else {
290
- // if we do not attempt to register immediately, registration fails
291
- // later unknown reason why, but this was the only difference between
292
- // using a react-native-permissions vs built-in permissions request in
293
- // a sequence of "request permissions" --> "register for messages" you
294
- // only want to request permission if you want to register for
295
- // messages, so we register directly now - see #7272
296
- dispatch_async(dispatch_get_main_queue(), ^{
297
- [[UIApplication sharedApplication] registerForRemoteNotifications];
298
- });
299
- [self hasPermission:resolve:reject];
300
- }
301
- }];
302
- }
303
-
304
- RCT_EXPORT_METHOD(registerForRemoteNotifications
305
- : (RCTPromiseResolveBlock)resolve
306
- : (RCTPromiseRejectBlock)reject) {
307
- #if TARGET_IPHONE_SIMULATOR
308
- #if !TARGET_CPU_ARM64
309
- // Register on this unsupported simulator, but no waiting for a token that won't arrive
310
- [[UIApplication sharedApplication] registerForRemoteNotifications];
311
- resolve(@([RCTConvert BOOL:@(YES)]));
312
- return;
313
- #endif
314
- DLog(@"RNFBMessaging registerForRemoteNotifications ARM64 Simulator detected, attempting real "
315
- @"registration. macOS13+ / iOS16+ / M1 mac required or will timeout.")
316
- #endif
317
- if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == YES) {
318
- DLog(@"RNFBMessaging registerForRemoteNotifications - already registered.");
319
- resolve(@([RCTConvert BOOL:@(YES)]));
320
- return;
321
- }
322
- else {
323
- [[RNFBMessagingAppDelegate sharedInstance] setPromiseResolve:resolve andPromiseReject:reject];
324
- }
325
-
326
- // Apple docs recommend that registerForRemoteNotifications is always called on app start
327
- // regardless of current status
328
- dispatch_async(dispatch_get_main_queue(), ^{
329
- // Sometimes the registration never completes, which deserves separate attention in other
330
- // areas. This area should protect itself against hanging forever regardless. Just in case,
331
- // check in after a delay and cleanup if required
332
- dispatch_after(
333
- dispatch_time(DISPATCH_TIME_NOW, 10.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
334
- if ([RNFBMessagingAppDelegate sharedInstance].registerPromiseResolver != nil) {
335
- // if we got here and resolve/reject are still set, unset, log failure, reject
336
- DLog(@"RNFBMessaging dispatch_after block: we appear to have timed out. Rejecting");
337
- [[RNFBMessagingAppDelegate sharedInstance] setPromiseResolve:nil andPromiseReject:nil];
338
-
339
- [RNFBSharedUtils
340
- rejectPromiseWithUserInfo:reject
341
- userInfo:[@{
342
- @"code" : @"unknown-error",
343
- @"message" :
344
- @"registerDeviceForRemoteMessages requested but "
345
- @"system did not respond. Possibly missing permission."
346
- } mutableCopy]];
347
- return;
348
- } else {
349
- DLog(@"RNFBMessaging dispatch_after: registerDeviceForRemoteMessages handled.");
350
- return;
351
- }
352
- });
353
-
354
- [[UIApplication sharedApplication] registerForRemoteNotifications];
355
- });
356
- }
357
-
358
- RCT_EXPORT_METHOD(unregisterForRemoteNotifications
359
- : (RCTPromiseResolveBlock)resolve
360
- : (RCTPromiseRejectBlock)reject) {
361
- [[UIApplication sharedApplication] unregisterForRemoteNotifications];
362
- resolve(nil);
363
- }
364
-
365
- RCT_EXPORT_METHOD(hasPermission : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
366
- [[UNUserNotificationCenter currentNotificationCenter]
367
- getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *_Nonnull settings) {
368
- NSNumber *authorizedStatus = @-1;
369
- if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
370
- authorizedStatus = @-1;
371
- } else if (settings.authorizationStatus == UNAuthorizationStatusDenied) {
372
- authorizedStatus = @0;
373
- } else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
374
- authorizedStatus = @1;
375
- } else if (settings.authorizationStatus == UNAuthorizationStatusProvisional) {
376
- authorizedStatus = @2;
377
- }
378
-
379
- if (@available(iOS 14.0, macCatalyst 14.0, *)) {
380
- if (settings.authorizationStatus == UNAuthorizationStatusEphemeral) {
381
- authorizedStatus = @3;
382
- }
383
- }
384
-
385
- resolve(authorizedStatus);
386
- }];
387
- }
388
-
389
- RCT_EXPORT_METHOD(subscribeToTopic
390
- : (NSString *)topic
391
- : (RCTPromiseResolveBlock)resolve
392
- : (RCTPromiseRejectBlock)reject) {
393
- [[FIRMessaging messaging] subscribeToTopic:topic
394
- completion:^(NSError *error) {
395
- if (error) {
396
- [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
397
- } else {
398
- resolve(nil);
399
- }
400
- }];
401
- }
402
-
403
- RCT_EXPORT_METHOD(unsubscribeFromTopic
404
- : (NSString *)topic
405
- : (RCTPromiseResolveBlock)resolve
406
- : (RCTPromiseRejectBlock)reject) {
407
- [[FIRMessaging messaging] unsubscribeFromTopic:topic
408
- completion:^(NSError *error) {
409
- if (error) {
410
- [RNFBSharedUtils rejectPromiseWithNSError:reject
411
- error:error];
412
- } else {
413
- resolve(nil);
414
- }
415
- }];
416
- }
417
-
418
- RCT_EXPORT_METHOD(setDeliveryMetricsExportToBigQuery
419
- : (BOOL)enabled
420
- : (RCTPromiseResolveBlock)resolve
421
- : (RCTPromiseRejectBlock)reject) {
422
- @try {
423
- _isDeliveryMetricsExportToBigQueryEnabled = enabled;
424
- } @catch (NSException *exception) {
425
- return [RNFBSharedUtils rejectPromiseWithExceptionDict:reject exception:exception];
426
- }
427
-
428
- return resolve([NSNull null]);
429
- }
430
-
431
- @end
@@ -1,32 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import <Firebase/Firebase.h>
19
- #import <Foundation/Foundation.h>
20
- #import <React/RCTBridgeModule.h>
21
-
22
- @interface RNFBMessagingSerializer : NSObject
23
-
24
- + (NSData *)APNSTokenDataFromNSString:(NSString *)token;
25
-
26
- + (NSString *)APNSTokenFromNSData:(NSData *)tokenData;
27
-
28
- + (NSDictionary *)notificationToDict:(UNNotification *)notification;
29
-
30
- + (NSDictionary *)remoteMessageUserInfoToDict:(NSDictionary *)userInfo;
31
-
32
- @end
@@ -1,235 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import "RNFBMessagingSerializer.h"
19
- #import <React/RCTConvert.h>
20
-
21
- @implementation RNFBMessagingSerializer
22
-
23
- + (NSData *)APNSTokenDataFromNSString:(NSString *)token {
24
- NSString *string = [token lowercaseString];
25
- NSMutableData *data = [NSMutableData new];
26
- unsigned char whole_byte;
27
- char byte_chars[3] = {'\0', '\0', '\0'};
28
- NSUInteger i = 0;
29
- NSUInteger length = string.length;
30
- while (i < length - 1) {
31
- char c = [string characterAtIndex:i++];
32
- if (c < '0' || (c > '9' && c < 'a') || c > 'f') continue;
33
- byte_chars[0] = c;
34
- byte_chars[1] = [string characterAtIndex:i++];
35
- whole_byte = strtol(byte_chars, NULL, 16);
36
- [data appendBytes:&whole_byte length:1];
37
- }
38
- return data;
39
- }
40
-
41
- + (NSString *)APNSTokenFromNSData:(NSData *)tokenData {
42
- const char *data = [tokenData bytes];
43
-
44
- NSMutableString *token = [NSMutableString string];
45
- for (NSInteger i = 0; i < tokenData.length; i++) {
46
- [token appendFormat:@"%02.2hhX", data[i]];
47
- }
48
-
49
- return [token copy];
50
- }
51
-
52
- + (NSDictionary *)notificationToDict:(UNNotification *)notification {
53
- return [self remoteMessageUserInfoToDict:notification.request.content.userInfo];
54
- }
55
-
56
- + (NSDictionary *)remoteMessageUserInfoToDict:(NSDictionary *)userInfo {
57
- NSMutableDictionary *message = [[NSMutableDictionary alloc] init];
58
- NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
59
- NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
60
- NSMutableDictionary *notificationIOS = [[NSMutableDictionary alloc] init];
61
-
62
- // message.data
63
- for (id key in userInfo) {
64
- // message.messageId
65
- if ([key isEqualToString:@"gcm.message_id"] || [key isEqualToString:@"google.message_id"] ||
66
- [key isEqualToString:@"message_id"]) {
67
- message[@"messageId"] = userInfo[key];
68
- continue;
69
- }
70
-
71
- // message.messageType
72
- if ([key isEqualToString:@"message_type"]) {
73
- message[@"messageType"] = userInfo[key];
74
- continue;
75
- }
76
-
77
- // message.collapseKey
78
- if ([key isEqualToString:@"collapse_key"]) {
79
- message[@"collapseKey"] = userInfo[key];
80
- continue;
81
- }
82
-
83
- // message.from
84
- if ([key isEqualToString:@"from"] || [key isEqualToString:@"google.c.sender.id"]) {
85
- message[@"from"] = userInfo[key];
86
- continue;
87
- }
88
-
89
- // message.sentTime
90
- if ([key isEqualToString:@"google.c.a.ts"]) {
91
- message[@"sentTime"] = userInfo[key];
92
- continue;
93
- }
94
-
95
- // message.to
96
- if ([key isEqualToString:@"to"] || [key isEqualToString:@"google.to"]) {
97
- message[@"to"] = userInfo[key];
98
- continue;
99
- }
100
-
101
- // build data dict from remaining keys but skip keys that shouldn't be included in data
102
- if ([key isEqualToString:@"aps"] || [key hasPrefix:@"gcm."] || [key hasPrefix:@"google."]) {
103
- continue;
104
- }
105
- data[key] = userInfo[key];
106
- }
107
- message[@"data"] = data;
108
-
109
- if (userInfo[@"aps"] != nil) {
110
- NSDictionary *apsDict = userInfo[@"aps"];
111
- // message.category
112
- if (apsDict[@"category"] != nil) {
113
- message[@"category"] = apsDict[@"category"];
114
- }
115
-
116
- // message.threadId
117
- if (apsDict[@"thread-id"] != nil) {
118
- message[@"threadId"] = apsDict[@"thread-id"];
119
- }
120
-
121
- // message.contentAvailable
122
- if (apsDict[@"content-available"] != nil) {
123
- message[@"contentAvailable"] = @([RCTConvert BOOL:apsDict[@"content-available"]]);
124
- }
125
-
126
- // message.mutableContent
127
- if (apsDict[@"mutable-content"] != nil && [apsDict[@"mutable-content"] intValue] == 1) {
128
- message[@"mutableContent"] = @([RCTConvert BOOL:apsDict[@"mutable-content"]]);
129
- }
130
-
131
- // iOS only
132
- // message.notification.ios.badge
133
- if (apsDict[@"badge"] != nil) {
134
- notificationIOS[@"badge"] = apsDict[@"badge"];
135
- }
136
-
137
- // message.notification.*
138
- if (apsDict[@"alert"] != nil) {
139
- // can be a string or dictionary
140
- if ([apsDict[@"alert"] isKindOfClass:[NSString class]]) {
141
- // message.notification.title
142
- notification[@"title"] = apsDict[@"alert"];
143
- } else if ([apsDict[@"alert"] isKindOfClass:[NSDictionary class]]) {
144
- NSDictionary *apsAlertDict = apsDict[@"alert"];
145
-
146
- // message.notification.title
147
- if (apsAlertDict[@"title"] != nil) {
148
- notification[@"title"] = apsAlertDict[@"title"];
149
- }
150
-
151
- // message.notification.titleLocKey
152
- if (apsAlertDict[@"title-loc-key"] != nil) {
153
- notification[@"titleLocKey"] = apsAlertDict[@"title-loc-key"];
154
- }
155
-
156
- // message.notification.titleLocArgs
157
- if (apsAlertDict[@"title-loc-args"] != nil) {
158
- notification[@"titleLocArgs"] = apsAlertDict[@"title-loc-args"];
159
- }
160
-
161
- // message.notification.body
162
- if (apsAlertDict[@"body"] != nil) {
163
- notification[@"body"] = apsAlertDict[@"body"];
164
- }
165
-
166
- // message.notification.bodyLocKey
167
- if (apsAlertDict[@"loc-key"] != nil) {
168
- notification[@"bodyLocKey"] = apsAlertDict[@"loc-key"];
169
- }
170
-
171
- // message.notification.bodyLocArgs
172
- if (apsAlertDict[@"loc-args"] != nil) {
173
- notification[@"bodyLocArgs"] = apsAlertDict[@"loc-args"];
174
- }
175
-
176
- // iOS only
177
- // message.notification.ios.subtitle
178
- if (apsAlertDict[@"subtitle"] != nil) {
179
- notificationIOS[@"subtitle"] = apsAlertDict[@"subtitle"];
180
- }
181
-
182
- // iOS only
183
- // message.notification.ios.subtitleLocKey
184
- if (apsAlertDict[@"subtitle-loc-key"] != nil) {
185
- notificationIOS[@"subtitleLocKey"] = apsAlertDict[@"subtitle-loc-key"];
186
- }
187
-
188
- // iOS only
189
- // message.notification.ios.subtitleLocArgs
190
- if (apsAlertDict[@"subtitle-loc-args"] != nil) {
191
- notificationIOS[@"subtitleLocArgs"] = apsAlertDict[@"subtitle-loc-args"];
192
- }
193
- }
194
- }
195
-
196
- // message.notification.ios.sound
197
- if (apsDict[@"sound"] != nil) {
198
- if ([apsDict[@"sound"] isKindOfClass:[NSString class]]) {
199
- // message.notification.ios.sound
200
- notification[@"sound"] = apsDict[@"sound"];
201
- } else if ([apsDict[@"sound"] isKindOfClass:[NSDictionary class]]) {
202
- NSDictionary *apsSoundDict = apsDict[@"sound"];
203
- NSMutableDictionary *notificationIOSSound = [[NSMutableDictionary alloc] init];
204
-
205
- // message.notification.ios.sound.name String
206
- if (apsSoundDict[@"name"] != nil) {
207
- notificationIOSSound[@"name"] = apsSoundDict[@"name"];
208
- }
209
-
210
- // message.notification.ios.sound.critical Boolean
211
- if (apsSoundDict[@"critical"] != nil) {
212
- notificationIOSSound[@"critical"] = @([RCTConvert BOOL:apsSoundDict[@"critical"]]);
213
- }
214
-
215
- // message.notification.ios.sound.volume Number
216
- if (apsSoundDict[@"volume"] != nil) {
217
- notificationIOSSound[@"volume"] = apsSoundDict[@"volume"];
218
- }
219
-
220
- // message.notification.ios.sound
221
- notificationIOS[@"sound"] = notificationIOSSound;
222
- }
223
- }
224
- }
225
- if ([notificationIOS count] > 0) {
226
- notification[@"ios"] = notificationIOS;
227
- }
228
- if ([notification count] > 0) {
229
- message[@"notification"] = notification;
230
- }
231
-
232
- return message;
233
- }
234
-
235
- @end