Skip to content

parse interruptionLevel field to allow time-sensitive notifications #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ios/RCTConvert+Notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
+ (NSCalendarUnit)NSCalendarUnit:(id)json;
@end

@interface RCTConvert (UNNotificationInterruptionLevel)
+ (UNNotificationInterruptionLevel)UNNotificationInterruptionLevel:(id)json API_AVAILABLE(ios(15.0));
@end

/**
* Type deprecated in iOS 10.0
* TODO: This method will be removed in the next major version
Expand Down
21 changes: 21 additions & 0 deletions ios/RCTConvert+Notification.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ @implementation RCTConvert (NSCalendarUnit)
@end


@implementation RCTConvert (UNNotificationInterruptionLevel)

RCT_ENUM_CONVERTER(UNNotificationInterruptionLevel,
(@{
@"passive": @(UNNotificationInterruptionLevelPassive),
@"active": @(UNNotificationInterruptionLevelActive),
@"timeSensitive": @(UNNotificationInterruptionLevelTimeSensitive),
@"critical": @(UNNotificationInterruptionLevelCritical)
}),
0,
integerValue)

@end


/**
* Type deprecated in iOS 10.0
Expand Down Expand Up @@ -106,6 +120,13 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
content.badge = [RCTConvert NSNumber:details[@"badge"]];
content.categoryIdentifier = [RCTConvert NSString:details[@"category"]];

if (@available(iOS 15.0, *)) {
UNNotificationInterruptionLevel interruptionLevel =[RCTConvert UNNotificationInterruptionLevel:details[@"interruptionLevel"]];
if(interruptionLevel) {
content.interruptionLevel = interruptionLevel;
}
}

NSString* threadIdentifier = [RCTConvert NSString:details[@"threadId"]];
if (threadIdentifier){
content.threadIdentifier = threadIdentifier;
Expand Down