Skip to content

Commit 71e853a

Browse files
authored
parse interruptionLevel field to allow time-sensitive notifications (#349)
1 parent dd46810 commit 71e853a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ios/RCTConvert+Notification.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
+ (NSCalendarUnit)NSCalendarUnit:(id)json;
1414
@end
1515

16+
@interface RCTConvert (UNNotificationInterruptionLevel)
17+
+ (UNNotificationInterruptionLevel)UNNotificationInterruptionLevel:(id)json API_AVAILABLE(ios(15.0));
18+
@end
19+
1620
/**
1721
* Type deprecated in iOS 10.0
1822
* TODO: This method will be removed in the next major version

ios/RCTConvert+Notification.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ @implementation RCTConvert (NSCalendarUnit)
2424
@end
2525

2626

27+
@implementation RCTConvert (UNNotificationInterruptionLevel)
28+
29+
RCT_ENUM_CONVERTER(UNNotificationInterruptionLevel,
30+
(@{
31+
@"passive": @(UNNotificationInterruptionLevelPassive),
32+
@"active": @(UNNotificationInterruptionLevelActive),
33+
@"timeSensitive": @(UNNotificationInterruptionLevelTimeSensitive),
34+
@"critical": @(UNNotificationInterruptionLevelCritical)
35+
}),
36+
0,
37+
integerValue)
38+
39+
@end
40+
2741

2842
/**
2943
* Type deprecated in iOS 10.0
@@ -110,6 +124,13 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
110124
content.badge = [RCTConvert NSNumber:details[@"badge"]];
111125
content.categoryIdentifier = [RCTConvert NSString:details[@"category"]];
112126

127+
if (@available(iOS 15.0, *)) {
128+
UNNotificationInterruptionLevel interruptionLevel =[RCTConvert UNNotificationInterruptionLevel:details[@"interruptionLevel"]];
129+
if(interruptionLevel) {
130+
content.interruptionLevel = interruptionLevel;
131+
}
132+
}
133+
113134
NSString* threadIdentifier = [RCTConvert NSString:details[@"threadId"]];
114135
if (threadIdentifier){
115136
content.threadIdentifier = threadIdentifier;

0 commit comments

Comments
 (0)