From 00224b143d4ac5889707a3cf187629d2bc9ac5d4 Mon Sep 17 00:00:00 2001 From: Ben Wernsman Date: Tue, 15 Feb 2022 16:55:23 -0600 Subject: [PATCH 1/3] Make notifications time zone agnostic --- README.md | 1 + ios/RCTConvert+Notification.m | 4 ++++ js/types.js | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 1975a2dc..95f8d23b 100644 --- a/README.md +++ b/README.md @@ -341,6 +341,7 @@ request is an object containing: - `isCritical` : If true, the notification sound be played even when the device is locked, muted, or has Do Not Disturb enabled. - `criticalSoundVolume` : A number between 0 and 1 for volume of critical notification. Default volume will be used if not specified. - `userInfo` : An object containing additional notification data. +- `isTimeZoneAgnostic` : If true, fireDate adjusted automatically upon time zone changes (e.g. for an alarm clock). request.repeatsComponent is an object containing (each field is optionnal): diff --git a/ios/RCTConvert+Notification.m b/ios/RCTConvert+Notification.m index b0b81f54..5a3b2d9e 100644 --- a/ios/RCTConvert+Notification.m +++ b/ios/RCTConvert+Notification.m @@ -35,6 +35,7 @@ + (UILocalNotification *)UILocalNotification:(id)json { NSDictionary *details = [self NSDictionary:json]; BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]]; + BOOL isTimeZoneAgnostic = [RCTConvert BOOL:details[@"isTimeZoneAgnostic"]]; UILocalNotification *notification = [UILocalNotification new]; notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]]; notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date]; @@ -49,6 +50,9 @@ + (UILocalNotification *)UILocalNotification:(id)json if (!isSilent) { notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName; } + if (isTimeZoneAgnostic) { + notification.timeZone = [NSTimeZone defaultTimeZone]; + } return notification; } diff --git a/js/types.js b/js/types.js index df3545d0..eea09a13 100644 --- a/js/types.js +++ b/js/types.js @@ -74,6 +74,10 @@ export type NotificationRequest = {| * Optional data to be added to the notification */ userInfo?: Object, + /** + * FireDate adjusted automatically upon time zone changes (e.g. for an alarm clock). + */ + isTimeZoneAgnostic?: boolean, |}; /** From 41794ed935a338a9de5ce9839f7f3315209d7590 Mon Sep 17 00:00:00 2001 From: Ben Wernsman Date: Tue, 15 Feb 2022 16:59:43 -0600 Subject: [PATCH 2/3] Fixed spacing --- ios/RCTConvert+Notification.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/RCTConvert+Notification.m b/ios/RCTConvert+Notification.m index 5a3b2d9e..61fe13f5 100644 --- a/ios/RCTConvert+Notification.m +++ b/ios/RCTConvert+Notification.m @@ -50,8 +50,8 @@ + (UILocalNotification *)UILocalNotification:(id)json if (!isSilent) { notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName; } - if (isTimeZoneAgnostic) { - notification.timeZone = [NSTimeZone defaultTimeZone]; + if (isTimeZoneAgnostic) { + notification.timeZone = [NSTimeZone defaultTimeZone]; } return notification; } From f28d0ef59da1928ed082c4efcbd2b2e012c04819 Mon Sep 17 00:00:00 2001 From: Ben Wernsman Date: Tue, 15 Feb 2022 17:00:03 -0600 Subject: [PATCH 3/3] Updated spacing --- ios/RCTConvert+Notification.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RCTConvert+Notification.m b/ios/RCTConvert+Notification.m index 61fe13f5..2bfc31a4 100644 --- a/ios/RCTConvert+Notification.m +++ b/ios/RCTConvert+Notification.m @@ -52,7 +52,7 @@ + (UILocalNotification *)UILocalNotification:(id)json } if (isTimeZoneAgnostic) { notification.timeZone = [NSTimeZone defaultTimeZone]; - } + } return notification; }