react-native-macos 0.73.4 → 0.73.5
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/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js +33 -5
- package/Libraries/PushNotificationIOS/RCTPushNotificationManager.h +0 -3
- package/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm +181 -244
- package/React/Base/RCTVersion.m +1 -1
- package/ReactAndroid/gradle.properties +1 -1
- package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
- package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
- package/package.json +1 -1
|
@@ -20,17 +20,45 @@ type Permissions = {|
|
|
|
20
20
|
|
|
21
21
|
type Notification = {|
|
|
22
22
|
+alertTitle?: ?string,
|
|
23
|
-
// Actual type: string | number
|
|
24
|
-
+fireDate?: ?number,
|
|
25
23
|
+alertBody?: ?string,
|
|
26
|
-
+alertAction?: ?string,
|
|
27
24
|
+userInfo?: ?Object,
|
|
25
|
+
/**
|
|
26
|
+
* Identifier for the notification category. See the [Apple documentation](https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types)
|
|
27
|
+
* for more details.
|
|
28
|
+
*/
|
|
28
29
|
+category?: ?string,
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Actual type: string | number
|
|
32
|
+
*
|
|
33
|
+
* Schedule notifications using EITHER `fireDate` or `fireIntervalSeconds`.
|
|
34
|
+
* If both are specified, `fireDate` takes precedence.
|
|
35
|
+
* If you use `presentLocalNotification`, both will be ignored
|
|
36
|
+
* and the notification will be shown immediately.
|
|
37
|
+
*/
|
|
38
|
+
+fireDate?: ?number,
|
|
39
|
+
/**
|
|
40
|
+
* Seconds from now to display the notification.
|
|
41
|
+
*
|
|
42
|
+
* Schedule notifications using EITHER `fireDate` or `fireIntervalSeconds`.
|
|
43
|
+
* If both are specified, `fireDate` takes precedence.
|
|
44
|
+
* If you use `presentLocalNotification`, both will be ignored
|
|
45
|
+
* and the notification will be shown immediately.
|
|
46
|
+
*/
|
|
47
|
+
+fireIntervalSeconds?: ?number,
|
|
48
|
+
/** Badge count to display on the app icon. */
|
|
31
49
|
+applicationIconBadgeNumber?: ?number,
|
|
50
|
+
/** Whether to silence the notification sound. */
|
|
32
51
|
+isSilent?: ?boolean,
|
|
52
|
+
/**
|
|
53
|
+
* Custom notification sound to play. Write-only: soundName will be null when
|
|
54
|
+
* accessing already created notifications using getScheduledLocalNotifications
|
|
55
|
+
* or getDeliveredNotifications.
|
|
56
|
+
*/
|
|
33
57
|
+soundName?: ?string,
|
|
58
|
+
/** DEPRECATED. This was used for iOS's legacy UILocalNotification. */
|
|
59
|
+
+alertAction?: ?string,
|
|
60
|
+
/** DEPRECATED. Use `fireDate` or `fireIntervalSeconds` instead. */
|
|
61
|
+
+repeatInterval?: ?string,
|
|
34
62
|
|};
|
|
35
63
|
|
|
36
64
|
export interface Spec extends TurboModule {
|
|
@@ -16,9 +16,6 @@ typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
|
|
|
16
16
|
#endif // [macOS]
|
|
17
17
|
|
|
18
18
|
#if !TARGET_OS_UIKITFORMAC
|
|
19
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
20
|
-
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
|
|
21
|
-
#endif // [macOS]
|
|
22
19
|
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
|
|
23
20
|
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
|
|
24
21
|
#if !TARGET_OS_OSX // [macOS]
|
|
@@ -25,88 +25,66 @@ static NSString *const kRemoteNotificationRegistrationFailed = @"RemoteNotificat
|
|
|
25
25
|
static NSString *const kErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS";
|
|
26
26
|
|
|
27
27
|
#if !TARGET_OS_UIKITFORMAC
|
|
28
|
-
@implementation RCTConvert (NSCalendarUnit)
|
|
29
|
-
|
|
30
|
-
RCT_ENUM_CONVERTER(
|
|
31
|
-
NSCalendarUnit,
|
|
32
|
-
(@{
|
|
33
|
-
@"year" : @(NSCalendarUnitYear),
|
|
34
|
-
@"month" : @(NSCalendarUnitMonth),
|
|
35
|
-
@"week" : @(NSCalendarUnitWeekOfYear),
|
|
36
|
-
@"day" : @(NSCalendarUnitDay),
|
|
37
|
-
@"hour" : @(NSCalendarUnitHour),
|
|
38
|
-
@"minute" : @(NSCalendarUnitMinute)
|
|
39
|
-
}),
|
|
40
|
-
0,
|
|
41
|
-
integerValue)
|
|
42
|
-
|
|
43
|
-
@end
|
|
44
28
|
|
|
45
29
|
@interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
|
|
46
30
|
@property (nonatomic, strong) NSMutableDictionary *remoteNotificationCallbacks;
|
|
47
31
|
@end
|
|
48
32
|
|
|
49
|
-
@implementation RCTConvert (
|
|
33
|
+
@implementation RCTConvert (UNNotificationContent)
|
|
50
34
|
|
|
51
|
-
|
|
52
|
-
+ (UILocalNotification *)UILocalNotification:(id)json
|
|
35
|
+
+ (UNNotificationContent *)UNNotificationContent:(id)json
|
|
53
36
|
{
|
|
54
37
|
NSDictionary<NSString *, id> *details = [self NSDictionary:json];
|
|
55
38
|
BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
|
|
62
|
-
notification.category = [RCTConvert NSString:details[@"category"]];
|
|
63
|
-
notification.repeatInterval = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
|
|
39
|
+
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
|
|
40
|
+
content.title = [RCTConvert NSString:details[@"alertTitle"]];
|
|
41
|
+
content.body = [RCTConvert NSString:details[@"alertBody"]];
|
|
42
|
+
content.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
|
|
43
|
+
content.categoryIdentifier = [RCTConvert NSString:details[@"category"]];
|
|
64
44
|
if (details[@"applicationIconBadgeNumber"]) {
|
|
65
|
-
|
|
45
|
+
content.badge = [RCTConvert NSNumber:details[@"applicationIconBadgeNumber"]];
|
|
66
46
|
}
|
|
67
47
|
if (!isSilent) {
|
|
68
|
-
|
|
48
|
+
NSString *soundName = [RCTConvert NSString:details[@"soundName"]];
|
|
49
|
+
content.sound =
|
|
50
|
+
soundName ? [UNNotificationSound soundNamed:details[@"soundName"]] : [UNNotificationSound defaultSound];
|
|
69
51
|
}
|
|
70
|
-
|
|
52
|
+
|
|
53
|
+
return content;
|
|
71
54
|
}
|
|
72
|
-
|
|
73
|
-
+ (
|
|
55
|
+
|
|
56
|
+
+ (NSDictionary<NSString *, id> *)NSDictionaryForNotification:
|
|
57
|
+
(JS::NativePushNotificationManagerIOS::Notification &)notification
|
|
74
58
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
NSString *actionButtonTitle = [RCTConvert NSString:details[@"alertAction"]];
|
|
85
|
-
if (actionButtonTitle) {
|
|
86
|
-
notification.actionButtonTitle = actionButtonTitle;
|
|
59
|
+
// Note: alertAction is not set, as it is no longer relevant with UNNotification
|
|
60
|
+
NSMutableDictionary *notificationDict = [NSMutableDictionary new];
|
|
61
|
+
notificationDict[@"alertTitle"] = notification.alertTitle();
|
|
62
|
+
notificationDict[@"alertBody"] = notification.alertBody();
|
|
63
|
+
notificationDict[@"userInfo"] = notification.userInfo();
|
|
64
|
+
notificationDict[@"category"] = notification.category();
|
|
65
|
+
if (notification.fireIntervalSeconds()) {
|
|
66
|
+
notificationDict[@"fireIntervalSeconds"] = @(*notification.fireIntervalSeconds());
|
|
87
67
|
}
|
|
88
|
-
notification.
|
|
89
|
-
|
|
90
|
-
NSCalendarUnit calendarUnit = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
|
|
91
|
-
if (calendarUnit > 0) {
|
|
92
|
-
NSDateComponents *dateComponents = [NSDateComponents new];
|
|
93
|
-
[dateComponents setValue:1 forComponent:calendarUnit];
|
|
94
|
-
notification.deliveryRepeatInterval = dateComponents;
|
|
68
|
+
if (notification.fireDate()) {
|
|
69
|
+
notificationDict[@"fireDate"] = @(*notification.fireDate());
|
|
95
70
|
}
|
|
96
|
-
if (
|
|
97
|
-
|
|
71
|
+
if (notification.applicationIconBadgeNumber()) {
|
|
72
|
+
notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
|
|
98
73
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
74
|
+
if (notification.isSilent()) {
|
|
75
|
+
notificationDict[@"isSilent"] = @(*notification.isSilent());
|
|
76
|
+
if ([notificationDict[@"isSilent"] isEqualToNumber:@(NO)]) {
|
|
77
|
+
notificationDict[@"soundName"] = notification.soundName();
|
|
78
|
+
}
|
|
103
79
|
}
|
|
104
|
-
|
|
105
|
-
return notification;
|
|
80
|
+
return notificationDict;
|
|
106
81
|
}
|
|
107
|
-
|
|
82
|
+
|
|
83
|
+
@end
|
|
108
84
|
|
|
109
85
|
#if !TARGET_OS_OSX // [macOS]
|
|
86
|
+
@implementation RCTConvert (UIBackgroundFetchResult)
|
|
87
|
+
|
|
110
88
|
RCT_ENUM_CONVERTER(
|
|
111
89
|
UIBackgroundFetchResult,
|
|
112
90
|
(@{
|
|
@@ -116,9 +94,9 @@ RCT_ENUM_CONVERTER(
|
|
|
116
94
|
}),
|
|
117
95
|
UIBackgroundFetchResultNoData,
|
|
118
96
|
integerValue)
|
|
119
|
-
#endif // [macOS]
|
|
120
97
|
|
|
121
98
|
@end
|
|
99
|
+
#endif // [macOS]
|
|
122
100
|
#else
|
|
123
101
|
@interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
|
|
124
102
|
@end
|
|
@@ -126,8 +104,10 @@ RCT_ENUM_CONVERTER(
|
|
|
126
104
|
|
|
127
105
|
@implementation RCTPushNotificationManager
|
|
128
106
|
|
|
129
|
-
#if !TARGET_OS_UIKITFORMAC
|
|
107
|
+
#if !TARGET_OS_UIKITFORMAC
|
|
130
108
|
|
|
109
|
+
#if !TARGET_OS_OSX // [macOS]
|
|
110
|
+
/** DEPRECATED. UILocalNotification was deprecated in iOS 10. Please don't add new callsites. */
|
|
131
111
|
static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
|
|
132
112
|
{
|
|
133
113
|
NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
|
|
@@ -146,33 +126,7 @@ static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notificatio
|
|
|
146
126
|
formattedLocalNotification[@"remote"] = @NO;
|
|
147
127
|
return formattedLocalNotification;
|
|
148
128
|
}
|
|
149
|
-
|
|
150
|
-
static NSDictionary *RCTFormatUNNotification(UNNotification *notification)
|
|
151
|
-
{
|
|
152
|
-
NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary];
|
|
153
|
-
UNNotificationContent *content = notification.request.content;
|
|
154
|
-
|
|
155
|
-
formattedNotification[@"identifier"] = notification.request.identifier;
|
|
156
|
-
|
|
157
|
-
if (notification.date) {
|
|
158
|
-
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
159
|
-
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
|
|
160
|
-
NSString *dateString = [formatter stringFromDate:notification.date];
|
|
161
|
-
formattedNotification[@"date"] = dateString;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
formattedNotification[@"title"] = RCTNullIfNil(content.title);
|
|
165
|
-
formattedNotification[@"body"] = RCTNullIfNil(content.body);
|
|
166
|
-
formattedNotification[@"category"] = RCTNullIfNil(content.categoryIdentifier);
|
|
167
|
-
formattedNotification[@"thread-id"] = RCTNullIfNil(content.threadIdentifier);
|
|
168
|
-
formattedNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));
|
|
169
|
-
|
|
170
|
-
return formattedNotification;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
#endif // TARGET_OS_UIKITFORMAC
|
|
174
|
-
#if TARGET_OS_OSX // [macOS
|
|
175
|
-
|
|
129
|
+
#else // [macOS
|
|
176
130
|
static NSDictionary *RCTFormatUserNotification(NSUserNotification *notification)
|
|
177
131
|
{
|
|
178
132
|
NSMutableDictionary *formattedUserNotification = [NSMutableDictionary dictionary];
|
|
@@ -192,6 +146,60 @@ static NSDictionary *RCTFormatUserNotification(NSUserNotification *notification)
|
|
|
192
146
|
}
|
|
193
147
|
#endif // macOS]
|
|
194
148
|
|
|
149
|
+
/** For delivered notifications */
|
|
150
|
+
static NSDictionary<NSString *, id> *RCTFormatUNNotification(UNNotification *notification)
|
|
151
|
+
{
|
|
152
|
+
NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
|
|
153
|
+
if (notification.date) {
|
|
154
|
+
formattedLocalNotification[@"fireDate"] = RCTFormatNotificationDateFromNSDate(notification.date);
|
|
155
|
+
}
|
|
156
|
+
[formattedLocalNotification addEntriesFromDictionary:RCTFormatUNNotificationContent(notification.request.content)];
|
|
157
|
+
return formattedLocalNotification;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** For scheduled notification requests */
|
|
161
|
+
static NSDictionary<NSString *, id> *RCTFormatUNNotificationRequest(UNNotificationRequest *request)
|
|
162
|
+
{
|
|
163
|
+
NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
|
|
164
|
+
if (request.trigger) {
|
|
165
|
+
NSDate *triggerDate = nil;
|
|
166
|
+
if ([request.trigger isKindOfClass:[UNTimeIntervalNotificationTrigger class]]) {
|
|
167
|
+
triggerDate = [(UNTimeIntervalNotificationTrigger *)request.trigger nextTriggerDate];
|
|
168
|
+
} else if ([request.trigger isKindOfClass:[UNCalendarNotificationTrigger class]]) {
|
|
169
|
+
triggerDate = [(UNCalendarNotificationTrigger *)request.trigger nextTriggerDate];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (triggerDate) {
|
|
173
|
+
formattedLocalNotification[@"fireDate"] = RCTFormatNotificationDateFromNSDate(triggerDate);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
[formattedLocalNotification addEntriesFromDictionary:RCTFormatUNNotificationContent(request.content)];
|
|
177
|
+
return formattedLocalNotification;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static NSDictionary<NSString *, id> *RCTFormatUNNotificationContent(UNNotificationContent *content)
|
|
181
|
+
{
|
|
182
|
+
// Note: soundName is not set because this can't be read from UNNotificationSound.
|
|
183
|
+
// Note: alertAction is no longer relevant with UNNotification
|
|
184
|
+
NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
|
|
185
|
+
formattedLocalNotification[@"alertTitle"] = RCTNullIfNil(content.title);
|
|
186
|
+
formattedLocalNotification[@"alertBody"] = RCTNullIfNil(content.body);
|
|
187
|
+
formattedLocalNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));
|
|
188
|
+
formattedLocalNotification[@"category"] = content.categoryIdentifier;
|
|
189
|
+
formattedLocalNotification[@"applicationIconBadgeNumber"] = content.badge;
|
|
190
|
+
formattedLocalNotification[@"remote"] = @NO;
|
|
191
|
+
return formattedLocalNotification;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static NSString *RCTFormatNotificationDateFromNSDate(NSDate *date)
|
|
195
|
+
{
|
|
196
|
+
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
197
|
+
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
|
|
198
|
+
return [formatter stringFromDate:date];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#endif // TARGET_OS_UIKITFORMAC
|
|
202
|
+
|
|
195
203
|
RCT_EXPORT_MODULE()
|
|
196
204
|
|
|
197
205
|
- (dispatch_queue_t)methodQueue
|
|
@@ -235,12 +243,6 @@ RCT_EXPORT_MODULE()
|
|
|
235
243
|
];
|
|
236
244
|
}
|
|
237
245
|
|
|
238
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
239
|
-
+ (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
|
|
240
|
-
{
|
|
241
|
-
}
|
|
242
|
-
#endif // [macOS]
|
|
243
|
-
|
|
244
246
|
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
|
|
245
247
|
{
|
|
246
248
|
NSMutableString *hexString = [NSMutableString string];
|
|
@@ -278,16 +280,16 @@ RCT_EXPORT_MODULE()
|
|
|
278
280
|
object:self
|
|
279
281
|
userInfo:userInfo];
|
|
280
282
|
}
|
|
283
|
+
#endif // [macOS]
|
|
281
284
|
|
|
285
|
+
#if !TARGET_OS_OSX // [macOS]
|
|
282
286
|
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification
|
|
283
287
|
{
|
|
284
288
|
[[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
|
|
285
289
|
object:self
|
|
286
290
|
userInfo:RCTFormatLocalNotification(notification)];
|
|
287
291
|
}
|
|
288
|
-
|
|
289
|
-
#else // [macOS
|
|
290
|
-
|
|
292
|
+
#else // [macOS
|
|
291
293
|
+ (void)didReceiveUserNotification:(NSUserNotification *)notification
|
|
292
294
|
{
|
|
293
295
|
NSString *notificationName = notification.isRemote ? RCTRemoteNotificationReceived : kLocalNotificationReceived;
|
|
@@ -296,7 +298,6 @@ RCT_EXPORT_MODULE()
|
|
|
296
298
|
object:self
|
|
297
299
|
userInfo:userInfo];
|
|
298
300
|
}
|
|
299
|
-
|
|
300
301
|
#endif // macOS]
|
|
301
302
|
|
|
302
303
|
- (void)handleLocalNotificationReceived:(NSNotification *)notification
|
|
@@ -306,15 +307,13 @@ RCT_EXPORT_MODULE()
|
|
|
306
307
|
|
|
307
308
|
- (void)handleRemoteNotificationReceived:(NSNotification *)notification
|
|
308
309
|
{
|
|
310
|
+
#if !TARGET_OS_OSX // [macOS]
|
|
309
311
|
NSMutableDictionary *remoteNotification =
|
|
310
312
|
[NSMutableDictionary dictionaryWithDictionary:notification.userInfo[@"notification"]];
|
|
311
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
312
313
|
RCTRemoteNotificationCallback completionHandler = notification.userInfo[@"completionHandler"];
|
|
313
|
-
#endif // [macOS]
|
|
314
314
|
NSString *notificationId = [[NSUUID UUID] UUIDString];
|
|
315
315
|
remoteNotification[@"notificationId"] = notificationId;
|
|
316
316
|
remoteNotification[@"remote"] = @YES;
|
|
317
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
318
317
|
if (completionHandler) {
|
|
319
318
|
if (!self.remoteNotificationCallbacks) {
|
|
320
319
|
// Lazy initialization
|
|
@@ -322,9 +321,9 @@ RCT_EXPORT_MODULE()
|
|
|
322
321
|
}
|
|
323
322
|
self.remoteNotificationCallbacks[notificationId] = completionHandler;
|
|
324
323
|
}
|
|
325
|
-
#endif // [macOS]
|
|
326
324
|
|
|
327
325
|
[self sendEventWithName:@"remoteNotificationReceived" body:remoteNotification];
|
|
326
|
+
#endif // [macOS]
|
|
328
327
|
}
|
|
329
328
|
|
|
330
329
|
- (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
|
|
@@ -343,9 +342,9 @@ RCT_EXPORT_MODULE()
|
|
|
343
342
|
[self sendEventWithName:@"remoteNotificationRegistrationError" body:errorDetails];
|
|
344
343
|
}
|
|
345
344
|
|
|
346
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
347
345
|
RCT_EXPORT_METHOD(onFinishRemoteNotification : (NSString *)notificationId fetchResult : (NSString *)fetchResult)
|
|
348
346
|
{
|
|
347
|
+
#if !TARGET_OS_OSX // [macOS]
|
|
349
348
|
UIBackgroundFetchResult result = [RCTConvert UIBackgroundFetchResult:fetchResult];
|
|
350
349
|
RCTRemoteNotificationCallback completionHandler = self.remoteNotificationCallbacks[notificationId];
|
|
351
350
|
if (!completionHandler) {
|
|
@@ -354,8 +353,8 @@ RCT_EXPORT_METHOD(onFinishRemoteNotification : (NSString *)notificationId fetchR
|
|
|
354
353
|
}
|
|
355
354
|
completionHandler(result);
|
|
356
355
|
[self.remoteNotificationCallbacks removeObjectForKey:notificationId];
|
|
357
|
-
}
|
|
358
356
|
#endif // [macOS]
|
|
357
|
+
}
|
|
359
358
|
|
|
360
359
|
/**
|
|
361
360
|
* Update the application icon badge number on the home screen
|
|
@@ -401,33 +400,19 @@ RCT_EXPORT_METHOD(requestPermissions
|
|
|
401
400
|
// Add a listener to make sure that startObserving has been called
|
|
402
401
|
[self addListener:@"remoteNotificationsRegistered"];
|
|
403
402
|
|
|
404
|
-
|
|
405
|
-
UIUserNotificationType types = UIUserNotificationTypeNone;
|
|
403
|
+
UNAuthorizationOptions options = UNAuthorizationOptionNone;
|
|
406
404
|
|
|
407
405
|
if (permissions.alert()) {
|
|
408
|
-
|
|
406
|
+
options |= UNAuthorizationOptionAlert;
|
|
409
407
|
}
|
|
410
408
|
if (permissions.badge()) {
|
|
411
|
-
|
|
409
|
+
options |= UNAuthorizationOptionBadge;
|
|
412
410
|
}
|
|
413
411
|
if (permissions.sound()) {
|
|
414
|
-
|
|
412
|
+
options |= UNAuthorizationOptionSound;
|
|
415
413
|
}
|
|
416
|
-
#else
|
|
417
|
-
NSRemoteNotificationType types = NSRemoteNotificationTypeNone;
|
|
418
|
-
|
|
419
|
-
if (permissions.alert()) {
|
|
420
|
-
types |= NSRemoteNotificationTypeAlert;
|
|
421
|
-
}
|
|
422
|
-
if (permissions.badge()) {
|
|
423
|
-
types |= NSRemoteNotificationTypeBadge;
|
|
424
|
-
}
|
|
425
|
-
if (permissions.sound()) {
|
|
426
|
-
types |= NSRemoteNotificationTypeSound;
|
|
427
|
-
}
|
|
428
|
-
#endif // macOS]
|
|
429
414
|
[UNUserNotificationCenter.currentNotificationCenter
|
|
430
|
-
requestAuthorizationWithOptions:
|
|
415
|
+
requestAuthorizationWithOptions:options
|
|
431
416
|
completionHandler:^(BOOL granted, NSError *_Nullable error) {
|
|
432
417
|
if (error != NULL) {
|
|
433
418
|
reject(@"-1", @"Error - Push authorization request failed.", error);
|
|
@@ -496,108 +481,87 @@ static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(
|
|
|
496
481
|
};
|
|
497
482
|
}
|
|
498
483
|
|
|
499
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
500
484
|
RCT_EXPORT_METHOD(presentLocalNotification : (JS::NativePushNotificationManagerIOS::Notification &)notification)
|
|
501
485
|
{
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
if (notification.applicationIconBadgeNumber()) {
|
|
513
|
-
notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
|
|
514
|
-
}
|
|
515
|
-
if (notification.isSilent()) {
|
|
516
|
-
notificationDict[@"isSilent"] = @(*notification.isSilent());
|
|
517
|
-
if ([notificationDict[@"isSilent"] isEqualToNumber:@(NO)]) {
|
|
518
|
-
notificationDict[@"soundName"] = notification.soundName();
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
[RCTSharedApplication() presentLocalNotificationNow:[RCTConvert UILocalNotification:notificationDict]];
|
|
522
|
-
}
|
|
523
|
-
#else // [macOS
|
|
524
|
-
RCT_EXPORT_METHOD(presentLocalNotification:(NSUserNotification *)notification)
|
|
525
|
-
{
|
|
526
|
-
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
|
486
|
+
NSDictionary<NSString *, id> *notificationDict = [RCTConvert NSDictionaryForNotification:notification];
|
|
487
|
+
UNNotificationContent *content = [RCTConvert UNNotificationContent:notificationDict];
|
|
488
|
+
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1
|
|
489
|
+
repeats:NO];
|
|
490
|
+
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString]
|
|
491
|
+
content:content
|
|
492
|
+
trigger:trigger];
|
|
493
|
+
|
|
494
|
+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
495
|
+
[center addNotificationRequest:request withCompletionHandler:nil];
|
|
527
496
|
}
|
|
528
|
-
#endif // macOS]
|
|
529
497
|
|
|
530
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
531
498
|
RCT_EXPORT_METHOD(scheduleLocalNotification : (JS::NativePushNotificationManagerIOS::Notification &)notification)
|
|
532
499
|
{
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
notificationDict[@"
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
notificationDict[@"soundName"] = notification.soundName();
|
|
550
|
-
}
|
|
500
|
+
NSDictionary<NSString *, id> *notificationDict = [RCTConvert NSDictionaryForNotification:notification];
|
|
501
|
+
UNNotificationContent *content = [RCTConvert UNNotificationContent:notificationDict];
|
|
502
|
+
|
|
503
|
+
UNNotificationTrigger *trigger = nil;
|
|
504
|
+
if (notificationDict[@"fireDate"]) {
|
|
505
|
+
NSDate *fireDate = [RCTConvert NSDate:notificationDict[@"fireDate"]] ?: [NSDate date];
|
|
506
|
+
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
507
|
+
NSDateComponents *components =
|
|
508
|
+
[calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour |
|
|
509
|
+
NSCalendarUnitMinute | NSCalendarUnitSecond)
|
|
510
|
+
fromDate:fireDate];
|
|
511
|
+
trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];
|
|
512
|
+
} else if (notificationDict[@"fireIntervalSeconds"]) {
|
|
513
|
+
trigger = [UNTimeIntervalNotificationTrigger
|
|
514
|
+
triggerWithTimeInterval:[notificationDict[@"fireIntervalSeconds"] doubleValue]
|
|
515
|
+
repeats:NO];
|
|
551
516
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
[
|
|
517
|
+
|
|
518
|
+
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString]
|
|
519
|
+
content:content
|
|
520
|
+
trigger:trigger];
|
|
521
|
+
|
|
522
|
+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
523
|
+
[center addNotificationRequest:request withCompletionHandler:nil];
|
|
558
524
|
}
|
|
559
|
-
#endif // macOS]
|
|
560
525
|
|
|
561
526
|
RCT_EXPORT_METHOD(cancelAllLocalNotifications)
|
|
562
527
|
{
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
528
|
+
[[UNUserNotificationCenter currentNotificationCenter]
|
|
529
|
+
getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> *requests) {
|
|
530
|
+
NSMutableArray<NSString *> *notificationIdentifiersToCancel = [NSMutableArray new];
|
|
531
|
+
for (UNNotificationRequest *request in requests) {
|
|
532
|
+
[notificationIdentifiersToCancel addObject:request.identifier];
|
|
533
|
+
}
|
|
534
|
+
[[UNUserNotificationCenter currentNotificationCenter]
|
|
535
|
+
removePendingNotificationRequestsWithIdentifiers:notificationIdentifiersToCancel];
|
|
536
|
+
}];
|
|
570
537
|
}
|
|
571
538
|
|
|
572
539
|
RCT_EXPORT_METHOD(cancelLocalNotifications : (NSDictionary<NSString *, id> *)userInfo)
|
|
573
540
|
{
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
541
|
+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
542
|
+
[center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> *_Nonnull requests) {
|
|
543
|
+
NSMutableArray<NSString *> *notificationIdentifiersToCancel = [NSMutableArray new];
|
|
544
|
+
for (UNNotificationRequest *request in requests) {
|
|
545
|
+
NSDictionary<NSString *, id> *notificationInfo = request.content.userInfo;
|
|
546
|
+
// Note: we do this with a loop instead of just `isEqualToDictionary:`
|
|
547
|
+
// because we only require that all specified userInfo values match the
|
|
548
|
+
// notificationInfo values - notificationInfo may contain additional values
|
|
549
|
+
// which we don't care about.
|
|
550
|
+
__block BOOL shouldCancel = YES;
|
|
551
|
+
[userInfo enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
|
|
552
|
+
if (![notificationInfo[key] isEqual:obj]) {
|
|
553
|
+
shouldCancel = NO;
|
|
554
|
+
*stop = YES;
|
|
555
|
+
}
|
|
556
|
+
}];
|
|
557
|
+
|
|
558
|
+
if (shouldCancel) {
|
|
559
|
+
[notificationIdentifiersToCancel addObject:request.identifier];
|
|
589
560
|
}
|
|
590
|
-
}];
|
|
591
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
592
|
-
if (matchesAll) {
|
|
593
|
-
[RCTSharedApplication() cancelLocalNotification:notification];
|
|
594
|
-
}
|
|
595
|
-
#else // [macOS
|
|
596
|
-
if ([notification.identifier isEqualToString:userInfo[@"identifier"]] || matchesAll) {
|
|
597
|
-
[[NSUserNotificationCenter defaultUserNotificationCenter] removeScheduledNotification:notification];
|
|
598
561
|
}
|
|
599
|
-
|
|
600
|
-
|
|
562
|
+
|
|
563
|
+
[center removePendingNotificationRequestsWithIdentifiers:notificationIdentifiersToCancel];
|
|
564
|
+
}];
|
|
601
565
|
}
|
|
602
566
|
|
|
603
567
|
RCT_EXPORT_METHOD(getInitialNotification
|
|
@@ -631,50 +595,30 @@ RCT_EXPORT_METHOD(getInitialNotification
|
|
|
631
595
|
|
|
632
596
|
RCT_EXPORT_METHOD(getScheduledLocalNotifications : (RCTResponseSenderBlock)callback)
|
|
633
597
|
{
|
|
634
|
-
|
|
635
|
-
NSArray<
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
[formattedScheduledLocalNotifications
|
|
641
|
-
}
|
|
642
|
-
#else // [macOS
|
|
643
|
-
for (NSUserNotification *notification in [NSUserNotificationCenter defaultUserNotificationCenter].scheduledNotifications) {
|
|
644
|
-
[formattedScheduledLocalNotifications addObject:RCTFormatUserNotification(notification)];
|
|
645
|
-
}
|
|
646
|
-
#endif // macOS]
|
|
647
|
-
callback(@[ formattedScheduledLocalNotifications ]);
|
|
598
|
+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
599
|
+
[center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> *_Nonnull requests) {
|
|
600
|
+
NSMutableArray<NSDictionary *> *formattedScheduledLocalNotifications = [NSMutableArray new];
|
|
601
|
+
for (UNNotificationRequest *request in requests) {
|
|
602
|
+
[formattedScheduledLocalNotifications addObject:RCTFormatUNNotificationRequest(request)];
|
|
603
|
+
}
|
|
604
|
+
callback(@[ formattedScheduledLocalNotifications ]);
|
|
605
|
+
}];
|
|
648
606
|
}
|
|
649
607
|
|
|
650
608
|
RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
|
|
651
609
|
{
|
|
652
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
653
610
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
654
611
|
[center removeAllDeliveredNotifications];
|
|
655
|
-
#else // [macOS
|
|
656
|
-
[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
|
|
657
|
-
#endif // macOS]
|
|
658
612
|
}
|
|
659
613
|
|
|
660
614
|
RCT_EXPORT_METHOD(removeDeliveredNotifications : (NSArray<NSString *> *)identifiers)
|
|
661
615
|
{
|
|
662
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
663
616
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
664
617
|
[center removeDeliveredNotificationsWithIdentifiers:identifiers];
|
|
665
|
-
#else // [macOS
|
|
666
|
-
NSArray<NSUserNotification*> *notificationsToRemove = [[NSUserNotificationCenter defaultUserNotificationCenter].deliveredNotifications filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSUserNotification* evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
|
|
667
|
-
return [identifiers containsObject:evaluatedObject.identifier];
|
|
668
|
-
}]];
|
|
669
|
-
for (NSUserNotification *notification in notificationsToRemove) {
|
|
670
|
-
[[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:notification];
|
|
671
|
-
}
|
|
672
|
-
#endif // macOS]
|
|
673
618
|
}
|
|
674
619
|
|
|
675
620
|
RCT_EXPORT_METHOD(getDeliveredNotifications : (RCTResponseSenderBlock)callback)
|
|
676
621
|
{
|
|
677
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
678
622
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
679
623
|
[center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> *_Nonnull notifications) {
|
|
680
624
|
NSMutableArray<NSDictionary *> *formattedNotifications = [NSMutableArray new];
|
|
@@ -684,13 +628,6 @@ RCT_EXPORT_METHOD(getDeliveredNotifications : (RCTResponseSenderBlock)callback)
|
|
|
684
628
|
}
|
|
685
629
|
callback(@[ formattedNotifications ]);
|
|
686
630
|
}];
|
|
687
|
-
#else // [macOS
|
|
688
|
-
NSMutableArray<NSDictionary *> *formattedNotifications = [NSMutableArray new];
|
|
689
|
-
for (NSUserNotification *notification in [NSUserNotificationCenter defaultUserNotificationCenter].deliveredNotifications) {
|
|
690
|
-
[formattedNotifications addObject:RCTFormatUserNotification(notification)];
|
|
691
|
-
}
|
|
692
|
-
callback(@[formattedNotifications]);
|
|
693
|
-
#endif // macOS]
|
|
694
631
|
}
|
|
695
632
|
|
|
696
633
|
RCT_EXPORT_METHOD(getAuthorizationStatus : (RCTResponseSenderBlock)callback)
|
package/React/Base/RCTVersion.m
CHANGED