Skip to content

Commit 3d0ca9a

Browse files
authored
Make notifications time zone agnostic (#354)
1 parent b5af2ba commit 3d0ca9a

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ request is an object containing:
341341
- `isCritical` : If true, the notification sound be played even when the device is locked, muted, or has Do Not Disturb enabled.
342342
- `criticalSoundVolume` : A number between 0 and 1 for volume of critical notification. Default volume will be used if not specified.
343343
- `userInfo` : An object containing additional notification data.
344+
- `isTimeZoneAgnostic` : If true, fireDate adjusted automatically upon time zone changes (e.g. for an alarm clock).
344345

345346
request.repeatsComponent is an object containing (each field is optionnal):
346347

ios/RCTConvert+Notification.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ + (UILocalNotification *)UILocalNotification:(id)json
3535
{
3636
NSDictionary<NSString *, id> *details = [self NSDictionary:json];
3737
BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
38+
BOOL isTimeZoneAgnostic = [RCTConvert BOOL:details[@"isTimeZoneAgnostic"]];
3839
UILocalNotification *notification = [UILocalNotification new];
3940
notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]];
4041
notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
@@ -49,6 +50,9 @@ + (UILocalNotification *)UILocalNotification:(id)json
4950
if (!isSilent) {
5051
notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
5152
}
53+
if (isTimeZoneAgnostic) {
54+
notification.timeZone = [NSTimeZone defaultTimeZone];
55+
}
5256
return notification;
5357
}
5458

js/types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export type NotificationRequest = {|
7474
* Optional data to be added to the notification
7575
*/
7676
userInfo?: Object,
77+
/**
78+
* FireDate adjusted automatically upon time zone changes (e.g. for an alarm clock).
79+
*/
80+
isTimeZoneAgnostic?: boolean,
7781
|};
7882

7983
/**

0 commit comments

Comments
 (0)