Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ghivert/push-notification-ios
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: elsaapp/push-notification-ios
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on May 31, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    marcgreenstock Marc Greenstock
    Copy the full SHA
    e84e64f View commit details
  2. add weekday

    marcgreenstock committed May 31, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    marcgreenstock Marc Greenstock
    Copy the full SHA
    c6d3f70 View commit details

Commits on Jun 2, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    marcgreenstock Marc Greenstock
    Copy the full SHA
    39dd2b6 View commit details
Showing with 38 additions and 22 deletions.
  1. +13 −0 index.d.ts
  2. +24 −22 ios/RCTConvert+Notification.m
  3. +1 −0 js/types.js
13 changes: 13 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -174,6 +174,19 @@ export type NotificationRequest = {
* Must be used with fireDate.
*/
repeats?: boolean;
/**
* Define what components should be used in the fireDate during repeats.
* Must be used with repeats and fireDate.
*/
repeatsComponent?: {
month?: boolean;
day?: boolean;
hour?: boolean;
minute?: boolean;
second?: boolean;
nanosecond?: boolean;
weekday?: boolean;
};
/**
* Sets notification to be silent
*/
46 changes: 24 additions & 22 deletions ios/RCTConvert+Notification.m
Original file line number Diff line number Diff line change
@@ -62,14 +62,14 @@ + (UILocalNotification *)UILocalNotification:(id)json
+ (NSDictionary *)RCTFormatLocalNotification:(UILocalNotification *)notification
{
NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];

if (notification.fireDate) {
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
NSString *fireDateString = [formatter stringFromDate:notification.fireDate];
formattedLocalNotification[@"fireDate"] = fireDateString;
}

formattedLocalNotification[@"alertAction"] = RCTNullIfNil(notification.alertAction);
formattedLocalNotification[@"alertTitle"] = RCTNullIfNil(notification.alertTitle);
formattedLocalNotification[@"alertBody"] = RCTNullIfNil(notification.alertBody);
@@ -116,6 +116,7 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
BOOL minute = [RCTConvert BOOL:userDateComps[@"minute"]];
BOOL second = [RCTConvert BOOL:userDateComps[@"second"]];
BOOL nanosecond = [RCTConvert BOOL:userDateComps[@"nanosecond"]];
BOOL weekday = [RTCConvert BOOL:userDateComps[@"weekday"]];

content.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
if (!isSilent) {
@@ -132,14 +133,16 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
NSCalendarUnitDay |
NSCalendarUnitHour |
NSCalendarUnitMinute |
NSCalendarUnitSecond;
NSCalendarUnitSecond |
NSCalendarUnitWeekday;
NSCalendarUnit repeatDateComponents =
(month ? NSCalendarUnitMonth : 0) |
(day ? NSCalendarUnitDay : 0) |
(hour ? NSCalendarUnitHour : 0) |
(minute ? NSCalendarUnitMinute : 0) |
(second ? NSCalendarUnitSecond : 0) |
(nanosecond ? NSCalendarUnitNanosecond : 0);
(nanosecond ? NSCalendarUnitNanosecond : 0) |
(weekday ? NSCalendarUnitWeekday : 0);
NSDateComponents *triggerDate = fireDate
? [[NSCalendar currentCalendar]
components:(repeats ? repeatDateComponents : defaultDateComponents) | NSCalendarUnitTimeZone
@@ -158,9 +161,9 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
+ (NSDictionary *)RCTFormatUNNotificationRequest:(UNNotificationRequest*)request
{
NSMutableDictionary *formattedRequest = [NSMutableDictionary dictionary];

formattedRequest[@"id"] = RCTNullIfNil(request.identifier);

UNNotificationContent *content = request.content;
formattedRequest[@"title"] = RCTNullIfNil(content.title);
formattedRequest[@"subtitle"] = RCTNullIfNil(content.subtitle);
@@ -170,7 +173,7 @@ + (NSDictionary *)RCTFormatUNNotificationRequest:(UNNotificationRequest*)request
formattedRequest[@"category"] = RCTNullIfNil(content.categoryIdentifier);
formattedRequest[@"thread-id"] = RCTNullIfNil(content.threadIdentifier);
formattedRequest[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));

if (request.trigger) {
UNCalendarNotificationTrigger* trigger = (UNCalendarNotificationTrigger*)request.trigger;
NSDateFormatter *formatter = [NSDateFormatter new];
@@ -217,11 +220,11 @@ + (UNNotificationAction *)UNNotificationAction:(id)json
NSDictionary<NSString *, id> *details = [self NSDictionary:json];
NSString* identifier = [RCTConvert NSString:details[@"id"]];
NSString* title = [RCTConvert NSString:details[@"title"]];


UNNotificationActionOptions options = [RCTConvert UNNotificationActionOptions:details[@"options"]];
UNNotificationAction* action = details[@"textInput"] ? [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:options textInputButtonTitle:details[@"textInput"][@"buttonTitle"] textInputPlaceholder:details[@"textInput"][@"placeholder"]] : [UNNotificationAction actionWithIdentifier:identifier title:title options:options];

return action;
}

@@ -235,15 +238,15 @@ @implementation RCTConvert (UNNotificationCategory)
+ (UNNotificationCategory *)UNNotificationCategory:(id)json
{
NSDictionary<NSString *, id> *details = [self NSDictionary:json];

NSString* identifier = [RCTConvert NSString:details[@"id"]];
NSMutableArray* actions = [NSMutableArray new];
for (NSDictionary* action in [RCTConvert NSArray:details[@"actions"]]) {
[actions addObject:[RCTConvert UNNotificationAction:action]];
}

UNNotificationCategory* category = [UNNotificationCategory categoryWithIdentifier:identifier actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];

return category;
}

@@ -259,21 +262,21 @@ + (NSDictionary *)RCTFormatUNNotificationResponse:(UNNotificationResponse *)resp
UNNotification* notification = response.notification;
NSMutableDictionary *formattedResponse = [[RCTConvert RCTFormatUNNotification:notification] mutableCopy];
UNNotificationContent *content = notification.request.content;

NSMutableDictionary *userInfo = [content.userInfo mutableCopy];
userInfo[@"userInteraction"] = [NSNumber numberWithInt:1];
userInfo[@"actionIdentifier"] = response.actionIdentifier;

formattedResponse[@"badge"] = RCTNullIfNil(content.badge);
formattedResponse[@"sound"] = RCTNullIfNil(content.sound);
formattedResponse[@"userInfo"] = RCTNullIfNil(RCTJSONClean(userInfo));
formattedResponse[@"actionIdentifier"] = RCTNullIfNil(response.actionIdentifier);

NSString* userText = [response isKindOfClass:[UNTextInputNotificationResponse class]] ? ((UNTextInputNotificationResponse *)response).userText : nil;
if (userText) {
formattedResponse[@"userText"] = RCTNullIfNil(userText);
}

return formattedResponse;
}
@end
@@ -287,16 +290,16 @@ + (NSDictionary *)RCTFormatUNNotification:(UNNotification *)notification
{
NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary];
UNNotificationContent *content = notification.request.content;

formattedNotification[@"identifier"] = notification.request.identifier;

if (notification.date) {
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
NSString *dateString = [formatter stringFromDate:notification.date];
formattedNotification[@"date"] = dateString;
}

formattedNotification[@"title"] = RCTNullIfNil(content.title);
formattedNotification[@"subtitle"] = RCTNullIfNil(content.subtitle);
formattedNotification[@"body"] = RCTNullIfNil(content.body);
@@ -305,9 +308,8 @@ + (NSDictionary *)RCTFormatUNNotification:(UNNotification *)notification
formattedNotification[@"category"] = RCTNullIfNil(content.categoryIdentifier);
formattedNotification[@"thread-id"] = RCTNullIfNil(content.threadIdentifier);
formattedNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));

return formattedNotification;
}

@end

1 change: 1 addition & 0 deletions js/types.js
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ export type NotificationRequest = {|
minute?: boolean,
second?: boolean,
nanosecond?: boolean,
weekday?: boolean,
},
/**
* Sets notification to be silent