[notifications] Rename `onPressed` to `onOpened`
This commit is contained in:
parent
07bc258c08
commit
ee3b2932ef
|
@ -40,7 +40,7 @@ static NSString *const MESSAGING_NOTIFICATION_RECEIVED = @"messaging_notificatio
|
||||||
|
|
||||||
// Notifications
|
// Notifications
|
||||||
static NSString *const NOTIFICATIONS_NOTIFICATION_DISPLAYED = @"notifications_notification_displayed";
|
static NSString *const NOTIFICATIONS_NOTIFICATION_DISPLAYED = @"notifications_notification_displayed";
|
||||||
static NSString *const NOTIFICATIONS_NOTIFICATION_PRESSED = @"notifications_notification_pressed";
|
static NSString *const NOTIFICATIONS_NOTIFICATION_OPENED = @"notifications_notification_opened";
|
||||||
static NSString *const NOTIFICATIONS_NOTIFICATION_RECEIVED = @"notifications_notification_received";
|
static NSString *const NOTIFICATIONS_NOTIFICATION_RECEIVED = @"notifications_notification_received";
|
||||||
|
|
||||||
// AdMob
|
// AdMob
|
||||||
|
|
|
@ -49,7 +49,7 @@ RCT_EXPORT_MODULE();
|
||||||
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
||||||
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
|
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set static instance for use from AppDelegate
|
// Set static instance for use from AppDelegate
|
||||||
theRNFirebaseNotifications = self;
|
theRNFirebaseNotifications = self;
|
||||||
}
|
}
|
||||||
|
@ -75,18 +75,15 @@ RCT_EXPORT_MODULE();
|
||||||
if ([self isIOS89]) {
|
if ([self isIOS89]) {
|
||||||
NSString *event;
|
NSString *event;
|
||||||
if (RCTSharedApplication().applicationState == UIApplicationStateBackground) {
|
if (RCTSharedApplication().applicationState == UIApplicationStateBackground) {
|
||||||
// notification_displayed
|
|
||||||
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
|
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
|
||||||
} else if (RCTSharedApplication().applicationState == UIApplicationStateInactive) {
|
} else if (RCTSharedApplication().applicationState == UIApplicationStateInactive) {
|
||||||
// notification_displayed
|
event = NOTIFICATIONS_NOTIFICATION_OPENED;
|
||||||
event = NOTIFICATIONS_NOTIFICATION_PRESSED;
|
|
||||||
} else {
|
} else {
|
||||||
// notification_received
|
|
||||||
event = NOTIFICATIONS_NOTIFICATION_RECEIVED;
|
event = NOTIFICATIONS_NOTIFICATION_RECEIVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary *notification = [self parseUILocalNotification:localNotification];
|
NSDictionary *notification = [self parseUILocalNotification:localNotification];
|
||||||
if (event == NOTIFICATIONS_NOTIFICATION_PRESSED) {
|
if (event == NOTIFICATIONS_NOTIFICATION_OPENED) {
|
||||||
notification = @{
|
notification = @{
|
||||||
@"action": UNNotificationDefaultActionIdentifier,
|
@"action": UNNotificationDefaultActionIdentifier,
|
||||||
@"notification": notification
|
@"notification": notification
|
||||||
|
@ -105,17 +102,14 @@ RCT_EXPORT_MODULE();
|
||||||
[[RNFirebaseMessaging instance] didReceiveRemoteNotification:userInfo];
|
[[RNFirebaseMessaging instance] didReceiveRemoteNotification:userInfo];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *event;
|
NSString *event;
|
||||||
if (RCTSharedApplication().applicationState == UIApplicationStateBackground) {
|
if (RCTSharedApplication().applicationState == UIApplicationStateBackground) {
|
||||||
// notification_displayed
|
|
||||||
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
|
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
|
||||||
} else if ([self isIOS89]) {
|
} else if ([self isIOS89]) {
|
||||||
if (RCTSharedApplication().applicationState == UIApplicationStateInactive) {
|
if (RCTSharedApplication().applicationState == UIApplicationStateInactive) {
|
||||||
// notification_displayed
|
event = NOTIFICATIONS_NOTIFICATION_OPENED;
|
||||||
event = NOTIFICATIONS_NOTIFICATION_PRESSED;
|
|
||||||
} else {
|
} else {
|
||||||
// notification_received
|
|
||||||
event = NOTIFICATIONS_NOTIFICATION_RECEIVED;
|
event = NOTIFICATIONS_NOTIFICATION_RECEIVED;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,8 +121,8 @@ RCT_EXPORT_MODULE();
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary *notification = [self parseUserInfo:userInfo];
|
NSDictionary *notification = [self parseUserInfo:userInfo];
|
||||||
// For onPressed events, we set the default action name as iOS 8/9 has no concept of actions
|
// For onOpened events, we set the default action name as iOS 8/9 has no concept of actions
|
||||||
if (event == NOTIFICATIONS_NOTIFICATION_PRESSED) {
|
if (event == NOTIFICATIONS_NOTIFICATION_OPENED) {
|
||||||
notification = @{
|
notification = @{
|
||||||
@"action": UNNotificationDefaultActionIdentifier,
|
@"action": UNNotificationDefaultActionIdentifier,
|
||||||
@"notification": notification
|
@"notification": notification
|
||||||
|
@ -153,15 +147,15 @@ RCT_EXPORT_MODULE();
|
||||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
||||||
willPresentNotification:(UNNotification *)notification
|
willPresentNotification:(UNNotification *)notification
|
||||||
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
||||||
|
|
||||||
UNNotificationTrigger *trigger = notification.request.trigger;
|
UNNotificationTrigger *trigger = notification.request.trigger;
|
||||||
BOOL isFcm = trigger && [notification.request.trigger class] == [UNPushNotificationTrigger class];
|
BOOL isFcm = trigger && [notification.request.trigger class] == [UNPushNotificationTrigger class];
|
||||||
BOOL isScheduled = trigger && [notification.request.trigger class] == [UNCalendarNotificationTrigger class];
|
BOOL isScheduled = trigger && [notification.request.trigger class] == [UNCalendarNotificationTrigger class];
|
||||||
|
|
||||||
NSString *event;
|
NSString *event;
|
||||||
UNNotificationPresentationOptions options;
|
UNNotificationPresentationOptions options;
|
||||||
NSDictionary *message = [self parseUNNotification:notification];
|
NSDictionary *message = [self parseUNNotification:notification];
|
||||||
|
|
||||||
if (isFcm || isScheduled) {
|
if (isFcm || isScheduled) {
|
||||||
// If app is in the background
|
// If app is in the background
|
||||||
if (RCTSharedApplication().applicationState == UIApplicationStateBackground
|
if (RCTSharedApplication().applicationState == UIApplicationStateBackground
|
||||||
|
@ -183,7 +177,7 @@ RCT_EXPORT_MODULE();
|
||||||
// notification_displayed
|
// notification_displayed
|
||||||
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
|
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self sendJSEvent:self name:event body:message];
|
[self sendJSEvent:self name:event body:message];
|
||||||
completionHandler(options);
|
completionHandler(options);
|
||||||
}
|
}
|
||||||
|
@ -197,8 +191,8 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
|
||||||
withCompletionHandler:(void(^)())completionHandler {
|
withCompletionHandler:(void(^)())completionHandler {
|
||||||
#endif
|
#endif
|
||||||
NSDictionary *message = [self parseUNNotificationResponse:response];
|
NSDictionary *message = [self parseUNNotificationResponse:response];
|
||||||
|
|
||||||
[self sendJSEvent:self name:NOTIFICATIONS_NOTIFICATION_PRESSED body:message];
|
[self sendJSEvent:self name:NOTIFICATIONS_NOTIFICATION_OPENED body:message];
|
||||||
completionHandler();
|
completionHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +253,7 @@ RCT_EXPORT_METHOD(displayNotification:(NSDictionary*) notification
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(getBadge: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
RCT_EXPORT_METHOD(getBadge: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
resolve(@([RCTSharedApplication() applicationIconBadgeNumber]));
|
resolve(@([RCTSharedApplication() applicationIconBadgeNumber]));
|
||||||
|
@ -360,13 +354,13 @@ RCT_EXPORT_METHOD(scheduleNotification:(NSDictionary*) notification
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[RCTSharedApplication() setApplicationIconBadgeNumber:number];
|
[RCTSharedApplication() setApplicationIconBadgeNumber:number];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because of the time delay between the app starting and the bridge being initialised
|
// Because of the time delay between the app starting and the bridge being initialised
|
||||||
// we create a temporary instance of RNFirebaseNotifications.
|
// we create a temporary instance of RNFirebaseNotifications.
|
||||||
// With this temporary instance, we cache any events to be sent as soon as the bridge is set on the module
|
// With this temporary instance, we cache any events to be sent as soon as the bridge is set on the module
|
||||||
|
@ -374,14 +368,14 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
if (emitter.bridge) {
|
if (emitter.bridge) {
|
||||||
[RNFirebaseUtil sendJSEvent:emitter name:name body:body];
|
[RNFirebaseUtil sendJSEvent:emitter name:name body:body];
|
||||||
} else {
|
} else {
|
||||||
if ([name isEqualToString:NOTIFICATIONS_NOTIFICATION_PRESSED] && !initialNotification) {
|
if ([name isEqualToString:NOTIFICATIONS_NOTIFICATION_OPENED] && !initialNotification) {
|
||||||
initialNotification = body;
|
initialNotification = body;
|
||||||
}
|
}
|
||||||
// PRE-BRIDGE-EVENTS: Consider enabling this to allow events built up before the bridge is built to be sent to the JS side
|
// PRE-BRIDGE-EVENTS: Consider enabling this to allow events built up before the bridge is built to be sent to the JS side
|
||||||
// [pendingEvents addObject:@{@"name":name, @"body":body}];
|
// [pendingEvents addObject:@{@"name":name, @"body":body}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isIOS89 {
|
- (BOOL)isIOS89 {
|
||||||
return floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max;
|
return floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max;
|
||||||
}
|
}
|
||||||
|
@ -425,7 +419,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
NSNumber *fireDateNumber = schedule[@"fireDate"];
|
NSNumber *fireDateNumber = schedule[@"fireDate"];
|
||||||
NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:([fireDateNumber doubleValue] / 1000.0)];
|
NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:([fireDateNumber doubleValue] / 1000.0)];
|
||||||
localNotification.fireDate = fireDate;
|
localNotification.fireDate = fireDate;
|
||||||
|
|
||||||
NSString *interval = schedule[@"repeatInterval"];
|
NSString *interval = schedule[@"repeatInterval"];
|
||||||
if (interval) {
|
if (interval) {
|
||||||
if ([interval isEqualToString:@"minute"]) {
|
if ([interval isEqualToString:@"minute"]) {
|
||||||
|
@ -438,9 +432,9 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
localNotification.repeatInterval = NSCalendarUnitWeekday;
|
localNotification.repeatInterval = NSCalendarUnitWeekday;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return localNotification;
|
return localNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +464,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
NSString *identifier = a[@"identifier"];
|
NSString *identifier = a[@"identifier"];
|
||||||
NSURL *url = [NSURL URLWithString:a[@"url"]];
|
NSURL *url = [NSURL URLWithString:a[@"url"]];
|
||||||
NSDictionary *options = a[@"options"];
|
NSDictionary *options = a[@"options"];
|
||||||
|
|
||||||
NSError *error;
|
NSError *error;
|
||||||
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:identifier URL:url options:options error:&error];
|
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:identifier URL:url options:options error:&error];
|
||||||
if (attachment) {
|
if (attachment) {
|
||||||
|
@ -495,13 +489,13 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
content.threadIdentifier = ios[@"threadIdentifier"];
|
content.threadIdentifier = ios[@"threadIdentifier"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withSchedule) {
|
if (withSchedule) {
|
||||||
NSDictionary *schedule = notification[@"schedule"];
|
NSDictionary *schedule = notification[@"schedule"];
|
||||||
NSNumber *fireDateNumber = schedule[@"fireDate"];
|
NSNumber *fireDateNumber = schedule[@"fireDate"];
|
||||||
NSString *interval = schedule[@"repeatInterval"];
|
NSString *interval = schedule[@"repeatInterval"];
|
||||||
NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:([fireDateNumber doubleValue] / 1000.0)];
|
NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:([fireDateNumber doubleValue] / 1000.0)];
|
||||||
|
|
||||||
NSCalendarUnit calendarUnit;
|
NSCalendarUnit calendarUnit;
|
||||||
if (interval) {
|
if (interval) {
|
||||||
if ([interval isEqualToString:@"minute"]) {
|
if ([interval isEqualToString:@"minute"]) {
|
||||||
|
@ -517,7 +511,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
// Needs to match exactly to the secpmd
|
// Needs to match exactly to the secpmd
|
||||||
calendarUnit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
|
calendarUnit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDateComponents *components = [[NSCalendar currentCalendar] components:calendarUnit fromDate:fireDate];
|
NSDateComponents *components = [[NSCalendar currentCalendar] components:calendarUnit fromDate:fireDate];
|
||||||
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:interval];
|
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:interval];
|
||||||
return [UNNotificationRequest requestWithIdentifier:notification[@"notificationId"] content:content trigger:trigger];
|
return [UNNotificationRequest requestWithIdentifier:notification[@"notificationId"] content:content trigger:trigger];
|
||||||
|
@ -528,7 +522,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
|
|
||||||
- (NSDictionary*) parseUILocalNotification:(UILocalNotification *) localNotification {
|
- (NSDictionary*) parseUILocalNotification:(UILocalNotification *) localNotification {
|
||||||
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
if (localNotification.alertBody) {
|
if (localNotification.alertBody) {
|
||||||
notification[@"body"] = localNotification.alertBody;
|
notification[@"body"] = localNotification.alertBody;
|
||||||
}
|
}
|
||||||
|
@ -541,7 +535,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
if (localNotification.alertTitle) {
|
if (localNotification.alertTitle) {
|
||||||
notification[@"title"] = localNotification.alertTitle;
|
notification[@"title"] = localNotification.alertTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableDictionary *ios = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *ios = [[NSMutableDictionary alloc] init];
|
||||||
if (localNotification.alertAction) {
|
if (localNotification.alertAction) {
|
||||||
ios[@"alertAction"] = localNotification.alertAction;
|
ios[@"alertAction"] = localNotification.alertAction;
|
||||||
|
@ -559,28 +553,28 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
ios[@"launchImage"] = localNotification.alertLaunchImage;
|
ios[@"launchImage"] = localNotification.alertLaunchImage;
|
||||||
}
|
}
|
||||||
notification[@"ios"] = ios;
|
notification[@"ios"] = ios;
|
||||||
|
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*)parseUNNotificationResponse:(UNNotificationResponse *)response {
|
- (NSDictionary*)parseUNNotificationResponse:(UNNotificationResponse *)response {
|
||||||
NSMutableDictionary *notificationResponse = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *notificationResponse = [[NSMutableDictionary alloc] init];
|
||||||
NSDictionary *notification = [self parseUNNotification:response.notification];
|
NSDictionary *notification = [self parseUNNotification:response.notification];
|
||||||
notificationResponse[@"notification"] = notification;
|
notificationResponse[@"notification"] = notification;
|
||||||
notificationResponse[@"action"] = response.actionIdentifier;
|
notificationResponse[@"action"] = response.actionIdentifier;
|
||||||
|
|
||||||
return notificationResponse;
|
return notificationResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*)parseUNNotification:(UNNotification *)notification {
|
- (NSDictionary*)parseUNNotification:(UNNotification *)notification {
|
||||||
return [self parseUNNotificationRequest:notification.request];
|
return [self parseUNNotificationRequest:notification.request];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*) parseUNNotificationRequest:(UNNotificationRequest *) notificationRequest {
|
- (NSDictionary*) parseUNNotificationRequest:(UNNotificationRequest *) notificationRequest {
|
||||||
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
notification[@"notificationId"] = notificationRequest.identifier;
|
notification[@"notificationId"] = notificationRequest.identifier;
|
||||||
|
|
||||||
if (notificationRequest.content.body) {
|
if (notificationRequest.content.body) {
|
||||||
notification[@"body"] = notificationRequest.content.body;
|
notification[@"body"] = notificationRequest.content.body;
|
||||||
}
|
}
|
||||||
|
@ -605,9 +599,9 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
if (notificationRequest.content.title) {
|
if (notificationRequest.content.title) {
|
||||||
notification[@"title"] = notificationRequest.content.title;
|
notification[@"title"] = notificationRequest.content.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableDictionary *ios = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *ios = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
if (notificationRequest.content.attachments) {
|
if (notificationRequest.content.attachments) {
|
||||||
NSMutableArray *attachments = [[NSMutableArray alloc] init];
|
NSMutableArray *attachments = [[NSMutableArray alloc] init];
|
||||||
for (UNNotificationAttachment *a in notificationRequest.content.attachments) {
|
for (UNNotificationAttachment *a in notificationRequest.content.attachments) {
|
||||||
|
@ -619,7 +613,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
}
|
}
|
||||||
ios[@"attachments"] = attachments;
|
ios[@"attachments"] = attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notificationRequest.content.badge) {
|
if (notificationRequest.content.badge) {
|
||||||
ios[@"badge"] = notificationRequest.content.badge;
|
ios[@"badge"] = notificationRequest.content.badge;
|
||||||
}
|
}
|
||||||
|
@ -633,12 +627,12 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
ios[@"threadIdentifier"] = notificationRequest.content.threadIdentifier;
|
ios[@"threadIdentifier"] = notificationRequest.content.threadIdentifier;
|
||||||
}
|
}
|
||||||
notification[@"ios"] = ios;
|
notification[@"ios"] = ios;
|
||||||
|
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*)parseUserInfo:(NSDictionary *)userInfo {
|
- (NSDictionary*)parseUserInfo:(NSDictionary *)userInfo {
|
||||||
|
|
||||||
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
|
||||||
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
|
||||||
NSMutableDictionary *ios = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *ios = [[NSMutableDictionary alloc] init];
|
||||||
|
@ -698,7 +692,7 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray<NSString *> *)supportedEvents {
|
- (NSArray<NSString *> *)supportedEvents {
|
||||||
return @[NOTIFICATIONS_NOTIFICATION_DISPLAYED, NOTIFICATIONS_NOTIFICATION_PRESSED, NOTIFICATIONS_NOTIFICATION_RECEIVED];
|
return @[NOTIFICATIONS_NOTIFICATION_DISPLAYED, NOTIFICATIONS_NOTIFICATION_OPENED, NOTIFICATIONS_NOTIFICATION_RECEIVED];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL)requiresMainQueueSetup
|
+ (BOOL)requiresMainQueueSetup
|
||||||
|
@ -712,4 +706,3 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
||||||
@implementation RNFirebaseNotifications
|
@implementation RNFirebaseNotifications
|
||||||
@end
|
@end
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { generatePushID, isObject } from '../../utils';
|
||||||
|
|
||||||
import type { NativeNotification } from './types';
|
import type { NativeNotification } from './types';
|
||||||
|
|
||||||
export type NotificationPressed = {
|
export type NotificationOpened = {
|
||||||
action: string,
|
action: string,
|
||||||
notification: Notification,
|
notification: Notification,
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,10 +18,10 @@ import {
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
import type App from '../core/app';
|
import type App from '../core/app';
|
||||||
import type { NotificationPressed } from './Notification';
|
import type { NotificationOpened } from './Notification';
|
||||||
import type {
|
import type {
|
||||||
NativeNotification,
|
NativeNotification,
|
||||||
NativeNotificationPressed,
|
NativeNotificationOpened,
|
||||||
Schedule,
|
Schedule,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
|
@ -31,15 +31,15 @@ type OnNotificationObserver = {
|
||||||
next: OnNotification,
|
next: OnNotification,
|
||||||
};
|
};
|
||||||
|
|
||||||
type OnNotificationPressed = NotificationPressed => any;
|
type OnNotificationOpened = NotificationOpened => any;
|
||||||
|
|
||||||
type OnNotificationPressedObserver = {
|
type OnNotificationOpenedObserver = {
|
||||||
next: OnNotificationPressed,
|
next: OnNotificationOpened,
|
||||||
};
|
};
|
||||||
|
|
||||||
const NATIVE_EVENTS = [
|
const NATIVE_EVENTS = [
|
||||||
'notifications_notification_displayed',
|
'notifications_notification_displayed',
|
||||||
'notifications_notification_pressed',
|
'notifications_notification_opened',
|
||||||
'notifications_notification_received',
|
'notifications_notification_received',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -86,12 +86,12 @@ export default class Notifications extends ModuleBase {
|
||||||
|
|
||||||
SharedEventEmitter.addListener(
|
SharedEventEmitter.addListener(
|
||||||
// sub to internal native event - this fans out to
|
// sub to internal native event - this fans out to
|
||||||
// public event name: onNotificationPressed
|
// public event name: onNotificationOpened
|
||||||
'notifications_notification_pressed',
|
'notifications_notification_opened',
|
||||||
(notificationPressed: NativeNotificationPressed) => {
|
(notificationOpened: NativeNotificationOpened) => {
|
||||||
SharedEventEmitter.emit('onNotificationPressed', {
|
SharedEventEmitter.emit('OnNotificationOpened', {
|
||||||
action: notificationPressed.action,
|
action: notificationOpened.action,
|
||||||
notification: new Notification(notificationPressed.notification),
|
notification: new Notification(notificationOpened.notification),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -111,22 +111,22 @@ export default class Notifications extends ModuleBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel all notifications
|
* Cancel all notifications
|
||||||
* @returns {*}
|
|
||||||
*/
|
*/
|
||||||
cancelAllNotifications(): Promise<void> {
|
cancelAllNotifications(): void {
|
||||||
return getNativeModule(this).cancelAllNotifications();
|
getNativeModule(this).cancelAllNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel a notification by id.
|
* Cancel a notification by id.
|
||||||
* @param id
|
* @param notificationId
|
||||||
* @returns {*}
|
|
||||||
*/
|
*/
|
||||||
cancelNotification(notificationId: string): Promise<void> {
|
cancelNotification(notificationId: string): void {
|
||||||
if (!notificationId) {
|
if (!notificationId) {
|
||||||
return Promise.reject(new Error('Missing notificationId'));
|
throw new Error(
|
||||||
|
'Notifications: cancelNotification expects a `notificationId`'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return getNativeModule(this).cancelNotification(notificationId);
|
getNativeModule(this).cancelNotification(notificationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,8 +207,8 @@ export default class Notifications extends ModuleBase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
onNotificationPressed(
|
onNotificationOpened(
|
||||||
nextOrObserver: OnNotificationPressed | OnNotificationPressedObserver
|
nextOrObserver: OnNotificationOpened | OnNotificationOpenedObserver
|
||||||
): () => any {
|
): () => any {
|
||||||
let listener;
|
let listener;
|
||||||
if (isFunction(nextOrObserver)) {
|
if (isFunction(nextOrObserver)) {
|
||||||
|
@ -217,37 +217,37 @@ export default class Notifications extends ModuleBase {
|
||||||
listener = nextOrObserver.next;
|
listener = nextOrObserver.next;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Notifications.onNotificationPressed failed: First argument must be a function or observer object with a `next` function.'
|
'Notifications.onNotificationOpened failed: First argument must be a function or observer object with a `next` function.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger(this).info('Creating onNotificationPressed listener');
|
getLogger(this).info('Creating onNotificationOpened listener');
|
||||||
SharedEventEmitter.addListener('onNotificationPressed', listener);
|
SharedEventEmitter.addListener('onNotificationOpened', listener);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
getLogger(this).info('Removing onNotificationPressed listener');
|
getLogger(this).info('Removing onNotificationOpened listener');
|
||||||
SharedEventEmitter.removeListener('onNotificationPressed', listener);
|
SharedEventEmitter.removeListener('onNotificationOpened', listener);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all delivered notifications.
|
* Remove all delivered notifications.
|
||||||
* @returns {*}
|
|
||||||
*/
|
*/
|
||||||
removeAllDeliveredNotifications(): Promise<void> {
|
removeAllDeliveredNotifications(): void {
|
||||||
return getNativeModule(this).removeAllDeliveredNotifications();
|
getNativeModule(this).removeAllDeliveredNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a delivered notification.
|
* Remove a delivered notification.
|
||||||
* @param notificationId
|
* @param notificationId
|
||||||
* @returns {*}
|
|
||||||
*/
|
*/
|
||||||
removeDeliveredNotification(notificationId: string): Promise<void> {
|
removeDeliveredNotification(notificationId: string): void {
|
||||||
if (!notificationId) {
|
if (!notificationId) {
|
||||||
return Promise.reject(new Error('Missing notificationId'));
|
throw new Error(
|
||||||
|
'Notifications: removeDeliveredNotification expects a `notificationId`'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return getNativeModule(this).removeDeliveredNotification(notificationId);
|
getNativeModule(this).removeDeliveredNotification(notificationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -161,7 +161,7 @@ export type NativeNotification = {|
|
||||||
title: string,
|
title: string,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export type NativeNotificationPressed = {|
|
export type NativeNotificationOpened = {|
|
||||||
action: string,
|
action: string,
|
||||||
notification: NativeNotification,
|
notification: NativeNotification,
|
||||||
|};
|
|};
|
||||||
|
|
Loading…
Reference in New Issue