Commit f0f0b0e0 authored by yogevbd's avatar yogevbd

WIP

parent 235cffd8
#import "RCTConvert.h" #import "RCTConvert.h"
@import UserNotifications; @import UserNotifications;
@interface RCTConvert (UIUserNotificationActivationMode)
@end
@interface RCTConvert (UIUserNotificationActionContext)
@end
@interface RCTConvert (UIUserNotificationActionBehavior)
@end
@interface RCTConvert (UIMutableUserNotificationAction) @interface RCTConvert (UIMutableUserNotificationAction)
+ (UIMutableUserNotificationAction *)UIMutableUserNotificationAction:(id)json; + (UIMutableUserNotificationAction *)UIMutableUserNotificationAction:(id)json;
@end @end
...@@ -21,10 +9,6 @@ ...@@ -21,10 +9,6 @@
+ (UNNotificationCategory *)UNMutableUserNotificationCategory:(id)json; + (UNNotificationCategory *)UNMutableUserNotificationCategory:(id)json;
@end @end
@interface RCTConvert (UILocalNotification)
+ (UILocalNotification *)UILocalNotification:(id)json;
@end
@interface RCTConvert (UNNotificationRequest) @interface RCTConvert (UNNotificationRequest)
+ (UNNotificationRequest *)UNNotificationRequest:(id)json withId:(NSString*)notificationId; + (UNNotificationRequest *)UNNotificationRequest:(id)json withId:(NSString*)notificationId;
@end @end
......
#import "RCTConvert+Notifications.h" #import "RCTConvert+Notifications.h"
/*
* Converters for Interactive Notifications
*/
@implementation RCTConvert (UIUserNotificationActivationMode) @implementation RCTConvert (UIUserNotificationActivationMode)
RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{
@"foreground": @(UIUserNotificationActivationModeForeground), @"foreground": @(UIUserNotificationActivationModeForeground),
...@@ -10,13 +8,6 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{ ...@@ -10,13 +8,6 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{
}), UIUserNotificationActivationModeForeground, integerValue) }), UIUserNotificationActivationModeForeground, integerValue)
@end @end
//@implementation RCTConvert (UIUserNotificationActionContext)
//RCT_ENUM_CONVERTER(UIUserNotificationActionContext, (@{
// @"default": @(UIUserNotificationActionContextDefault),
// @"minimal": @(UIUserNotificationActionContextMinimal)
// }), UIUserNotificationActionContextDefault, integerValue)
//@end
@implementation RCTConvert (UNNotificationActionOptions) @implementation RCTConvert (UNNotificationActionOptions)
+ (UNNotificationActionOptions)UNUserNotificationActionOptions:(id)json { + (UNNotificationActionOptions)UNUserNotificationActionOptions:(id)json {
...@@ -37,8 +28,8 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{ ...@@ -37,8 +28,8 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{
@end @end
@implementation RCTConvert (UNMutableUserNotificationAction) @implementation RCTConvert (UNMutableUserNotificationAction)
+ (UNNotificationAction *)UNMutableUserNotificationAction:(id)json
{ + (UNNotificationAction *)UNMutableUserNotificationAction:(id)json {
UNNotificationAction* action; UNNotificationAction* action;
NSDictionary<NSString *, id> *details = [self NSDictionary:json]; NSDictionary<NSString *, id> *details = [self NSDictionary:json];
...@@ -48,15 +39,14 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{ ...@@ -48,15 +39,14 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{
action = [UNNotificationAction actionWithIdentifier:details[@"identifier"] title:details[@"title"] options:[RCTConvert UNUserNotificationActionOptions:details]]; action = [UNNotificationAction actionWithIdentifier:details[@"identifier"] title:details[@"title"] options:[RCTConvert UNUserNotificationActionOptions:details]];
} }
// action.behavior = [RCTConvert UIUserNotificationActionBehavior:details[@"behavior"]];
return action; return action;
} }
@end @end
@implementation RCTConvert (UNMutableUserNotificationCategory) @implementation RCTConvert (UNMutableUserNotificationCategory)
+ (UNNotificationCategory *)UNMutableUserNotificationCategory:(id)json
{ + (UNNotificationCategory *)UNMutableUserNotificationCategory:(id)json {
NSDictionary<NSString *, id> *details = [self NSDictionary:json]; NSDictionary<NSString *, id> *details = [self NSDictionary:json];
NSMutableArray* actions = [NSMutableArray new]; NSMutableArray* actions = [NSMutableArray new];
...@@ -68,39 +58,20 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{ ...@@ -68,39 +58,20 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{
return category; return category;
} }
@end
@implementation RCTConvert (UILocalNotification)
+ (UILocalNotification *)UILocalNotification:(id)json
{
NSDictionary<NSString *, id> *details = [self NSDictionary:json];
UILocalNotification* notification = [UILocalNotification new];
notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]];
notification.alertBody = [RCTConvert NSString:details[@"alertBody"]];
notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]];
notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
if ([RCTConvert BOOL:details[@"silent"]]) {
notification.soundName = nil;
}
notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]] ?: @{};
notification.category = [RCTConvert NSString:details[@"category"]];
return notification;
}
@end @end
@implementation RCTConvert (UNNotificationRequest) @implementation RCTConvert (UNNotificationRequest)
+ (UNNotificationRequest *)UNNotificationRequest:(id)json withId:(NSString*)notificationId + (UNNotificationRequest *)UNNotificationRequest:(id)json withId:(NSString*)notificationId
{ {
NSDictionary<NSString *, id> *details = [self NSDictionary:json]; NSDictionary<NSString *, id> *details = [self NSDictionary:json];
UNMutableNotificationContent *content = [UNMutableNotificationContent new]; UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.body = [RCTConvert NSString:details[@"alertBody"]]; content.body = [RCTConvert NSString:details[@"body"]];
content.title = [RCTConvert NSString:details[@"alertTitle"]]; content.title = [RCTConvert NSString:details[@"title"]];
content.sound = [RCTConvert NSString:details[@"soundName"]] content.sound = [RCTConvert NSString:details[@"sound"]]
? [UNNotificationSound soundNamed:[RCTConvert NSString:details[@"soundName"]]] ? [UNNotificationSound soundNamed:[RCTConvert NSString:details[@"sound"]]]
: [UNNotificationSound defaultSound]; : [UNNotificationSound defaultSound];
if ([RCTConvert BOOL:details[@"silent"]]) { if ([RCTConvert BOOL:details[@"silent"]]) {
content.sound = nil; content.sound = nil;
...@@ -124,9 +95,11 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{ ...@@ -124,9 +95,11 @@ RCT_ENUM_CONVERTER(UIUserNotificationActivationMode, (@{
return [UNNotificationRequest requestWithIdentifier:notificationId return [UNNotificationRequest requestWithIdentifier:notificationId
content:content trigger:trigger]; content:content trigger:trigger];
} }
@end @end
@implementation RCTConvert (UNNotification) @implementation RCTConvert (UNNotification)
+ (NSDictionary *)UNNotificationPayload:(UNNotification *)notification { + (NSDictionary *)UNNotificationPayload:(UNNotification *)notification {
NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary]; NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary];
UNNotificationContent *content = notification.request.content; UNNotificationContent *content = notification.request.content;
......
...@@ -54,21 +54,15 @@ ...@@ -54,21 +54,15 @@
} }
- (void)cancelAllLocalNotifications { - (void)cancelAllLocalNotifications {
[RCTSharedApplication() cancelAllLocalNotifications]; [_notificationCenter cancelAllLocalNotifications];
} }
- (void)isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { - (void)isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
BOOL ans = [[[UIApplication sharedApplication] currentUserNotificationSettings] types] != 0; [_notificationCenter isRegisteredForRemoteNotifications:resolve];
resolve(@(ans));
} }
- (void)checkPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { - (void)checkPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings]; [_notificationCenter checkPermissions:resolve];
resolve(@{
@"badge": @((currentSettings.types & UIUserNotificationTypeBadge) > 0),
@"sound": @((currentSettings.types & UIUserNotificationTypeSound) > 0),
@"alert": @((currentSettings.types & UIUserNotificationTypeAlert) > 0),
});
} }
- (void)removeAllDeliveredNotifications { - (void)removeAllDeliveredNotifications {
......
...@@ -4,7 +4,6 @@ static NSString* const RNRegistered = @"remoteNotificationsR ...@@ -4,7 +4,6 @@ static NSString* const RNRegistered = @"remoteNotificationsR
static NSString* const RNRegistrationFailed = @"remoteNotificationsRegistrationFailed"; static NSString* const RNRegistrationFailed = @"remoteNotificationsRegistrationFailed";
static NSString* const RNPushKitRegistered = @"pushKitRegistered"; static NSString* const RNPushKitRegistered = @"pushKitRegistered";
static NSString* const RNNotificationReceivedForeground = @"notificationReceivedForeground"; static NSString* const RNNotificationReceivedForeground = @"notificationReceivedForeground";
static NSString* const RNNotificationReceivedBackground = @"notificationReceivedBackground";
static NSString* const RNNotificationOpened = @"notificationOpened"; static NSString* const RNNotificationOpened = @"notificationOpened";
......
...@@ -9,7 +9,6 @@ RCT_EXPORT_MODULE(); ...@@ -9,7 +9,6 @@ RCT_EXPORT_MODULE();
RNRegistrationFailed, RNRegistrationFailed,
RNPushKitRegistered, RNPushKitRegistered,
RNNotificationReceivedForeground, RNNotificationReceivedForeground,
RNNotificationReceivedBackground,
RNNotificationOpened]; RNNotificationOpened];
} }
......
...@@ -4,11 +4,22 @@ ...@@ -4,11 +4,22 @@
@interface RNNotificationCenter : NSObject @interface RNNotificationCenter : NSObject
- (void)isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve;
- (void)requestPermissionsWithCategories:(NSArray *)json; - (void)requestPermissionsWithCategories:(NSArray *)json;
- (void)checkPermissions:(RCTPromiseResolveBlock)resolve;
- (void)sendLocalNotification:(NSDictionary *)notification withId:(NSString *)notificationId; - (void)sendLocalNotification:(NSDictionary *)notification withId:(NSString *)notificationId;
- (void)cancelLocalNotification:(NSString *)notificationId; - (void)cancelLocalNotification:(NSString *)notificationId;
- (void)removeAllDeliveredNotifications; - (void)removeAllDeliveredNotifications;
- (void)removeDeliveredNotifications:(NSArray<NSString *> *)identifiers; - (void)removeDeliveredNotifications:(NSArray<NSString *> *)identifiers;
- (void)getDeliveredNotifications:(RCTResponseSenderBlock)callback; - (void)getDeliveredNotifications:(RCTResponseSenderBlock)callback;
- (void)cancelAllLocalNotifications;
@end @end
...@@ -65,4 +65,28 @@ ...@@ -65,4 +65,28 @@
}]; }];
} }
- (void)cancelAllLocalNotifications {
[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
}
- (void)isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve {
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.alertSetting == UNNotificationSettingEnabled || settings.soundSetting == UNNotificationSettingEnabled || settings.badgeSetting == UNNotificationSettingEnabled) {
resolve(@(YES));
} else {
resolve(@(NO));
}
}];
}
- (void)checkPermissions:(RCTPromiseResolveBlock)resolve {
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
resolve(@{
@"badge": @(settings.badgeSetting == UNNotificationSettingEnabled),
@"sound": @(settings.soundSetting == UNNotificationSettingEnabled),
@"alert": @(settings.alertSetting == UNNotificationSettingEnabled),
});
}];
}
@end @end
...@@ -10,9 +10,9 @@ Example: ...@@ -10,9 +10,9 @@ Example:
```javascript ```javascript
let localNotification = NotificationsIOS.localNotification({ let localNotification = NotificationsIOS.localNotification({
alertBody: "Local notificiation!", body: "Local notificiation!",
alertTitle: "Local Notification Title", title: "Local Notification Title",
soundName: "chime.aiff", sound: "chime.aiff",
silent: false, silent: false,
category: "SOME_CATEGORY", category: "SOME_CATEGORY",
userInfo: { } userInfo: { }
...@@ -22,10 +22,10 @@ let localNotification = NotificationsIOS.localNotification({ ...@@ -22,10 +22,10 @@ let localNotification = NotificationsIOS.localNotification({
Notification object contains: Notification object contains:
- **`fireDate`**- The date and time when the system should deliver the notification (optinal - default is immidiate dispatch). - **`fireDate`**- The date and time when the system should deliver the notification (optinal - default is immidiate dispatch).
- `alertBody`- The message displayed in the notification alert. - `body`- The message displayed in the notification alert.
- `alertTitle`- The title of the notification, displayed in the notifications center. - `title`- The title of the notification, displayed in the notifications center.
- `alertAction`- The "action" displayed beneath an actionable notification on the lockscreen (e.g. "Slide to **open**"). Note that Apple no longer shows this in iOS 10. - `alertAction`- The "action" displayed beneath an actionable notification on the lockscreen (e.g. "Slide to **open**"). Note that Apple no longer shows this in iOS 10.
- `soundName`- The sound played when the notification is fired (optional -- will play default sound if unspecified). This must be the filename of a sound included in the application bundle; the sound must be 30 seconds or less and should be encoded with linear PCM or IMA4. - `sound`- The sound played when the notification is fired (optional -- will play default sound if unspecified). This must be the filename of a sound included in the application bundle; the sound must be 30 seconds or less and should be encoded with linear PCM or IMA4.
- `silent`- Whether the notification sound should be suppressed (optional). - `silent`- Whether the notification sound should be suppressed (optional).
- `category`- The category of this notification, required for [interactive notifications](#interactive--actionable-notifications-ios-only) (optional). - `category`- The category of this notification, required for [interactive notifications](#interactive--actionable-notifications-ios-only) (optional).
- `userInfo`- An optional object containing additional notification data. - `userInfo`- An optional object containing additional notification data.
...@@ -38,9 +38,9 @@ Example: ...@@ -38,9 +38,9 @@ Example:
```javascript ```javascript
let someLocalNotification = NotificationsIOS.localNotification({ let someLocalNotification = NotificationsIOS.localNotification({
alertBody: "Local notificiation!", body: "Local notificiation!",
alertTitle: "Local Notification Title", title: "Local Notification Title",
soundName: "chime.aiff", sound: "chime.aiff",
category: "SOME_CATEGORY", category: "SOME_CATEGORY",
userInfo: { } userInfo: { }
}); });
......
...@@ -13,11 +13,6 @@ let upvoteAction = new NotificationAction({ ...@@ -13,11 +13,6 @@ let upvoteAction = new NotificationAction({
activationMode: 'background', activationMode: 'background',
title: String.fromCodePoint(0x1F44D), title: String.fromCodePoint(0x1F44D),
identifier: 'UPVOTE_ACTION' identifier: 'UPVOTE_ACTION'
}, (action, completed) => {
NotificationsIOS.log('ACTION RECEIVED');
NotificationsIOS.log(JSON.stringify(action));
completed();
}); });
let replyAction = new NotificationAction({ let replyAction = new NotificationAction({
...@@ -30,11 +25,6 @@ let replyAction = new NotificationAction({ ...@@ -30,11 +25,6 @@ let replyAction = new NotificationAction({
placeholder: 'Insert message' placeholder: 'Insert message'
}, },
identifier: 'REPLY_ACTION' identifier: 'REPLY_ACTION'
}, (action, completed) => {
console.log('ACTION RECEIVED');
console.log(action);
completed();
}); });
class NotificationsExampleApp extends Component { class NotificationsExampleApp extends Component {
...@@ -75,11 +65,12 @@ class NotificationsExampleApp extends Component { ...@@ -75,11 +65,12 @@ class NotificationsExampleApp extends Component {
notifications: [...this.state.notifications, notification] notifications: [...this.state.notifications, notification]
}); });
completion({}); completion({alert: true, sound: false, badge: false});
} }
onNotificationOpened(notification) { onNotificationOpened(notification, completion, action) {
console.log('Notification Opened: ' + JSON.stringify(notification)); console.log('Notification Opened: ' + JSON.stringify(notification) + JSON.stringify(action));
completion();
} }
renderNotification(notification) { renderNotification(notification) {
...@@ -97,6 +88,8 @@ class NotificationsExampleApp extends Component { ...@@ -97,6 +88,8 @@ class NotificationsExampleApp extends Component {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Button title={'Request permissions'} onPress={this.requestPermissions} testID={'requestPermissions'}/> <Button title={'Request permissions'} onPress={this.requestPermissions} testID={'requestPermissions'}/>
<Button title={'Send local notification'} onPress={this.sendLocalNotification} testID={'sendLocalNotification'}/>
<Button title={'Remove all delivered notifications'} onPress={this.removeAllDeliveredNotifications}/>
{notifications} {notifications}
</View> </View>
); );
...@@ -111,23 +104,25 @@ class NotificationsExampleApp extends Component { ...@@ -111,23 +104,25 @@ class NotificationsExampleApp extends Component {
NotificationsIOS.requestPermissions([cat]); NotificationsIOS.requestPermissions([cat]);
} }
sendLocalNotification() {
NotificationsIOS.localNotification({
body: 'Local notificiation!',
title: 'Local Notification Title',
sound: 'chime.aiff',
category: 'SOME_CATEGORY',
userInfo: { }
});
}
removeAllDeliveredNotifications() {
NotificationsIOS.removeAllDeliveredNotifications();
}
componentWillUnmount() { componentWillUnmount() {
NotificationsIOS.removeEventListener('notificationReceivedForeground', this.onNotificationReceivedForeground.bind(this)); NotificationsIOS.removeEventListener('notificationReceivedForeground', this.onNotificationReceivedForeground.bind(this));
NotificationsIOS.removeEventListener('notificationOpened', this.onNotificationOpened.bind(this)); NotificationsIOS.removeEventListener('notificationOpened', this.onNotificationOpened.bind(this));
NotificationsIOS.removeEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this)); NotificationsIOS.removeEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this));
NotificationsIOS.removeEventListener('pushKitRegistered', this.onPushKitRegistered.bind(this)); NotificationsIOS.removeEventListener('pushKitRegistered', this.onPushKitRegistered.bind(this));
// NotificationsIOS.resetCategories();
}
_onNotification(notification) {
AlertIOS.alert(
'Notification Received',
'Alert message: ' + notification.getMessage(),
[{
text: 'Dismiss',
onPress: null,
}]
);
} }
} }
......
...@@ -12,30 +12,23 @@ export const DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT = 'remoteNotifications ...@@ -12,30 +12,23 @@ export const DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT = 'remoteNotifications
export const DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT = 'remoteNotificationsRegistrationFailed'; export const DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT = 'remoteNotificationsRegistrationFailed';
export const DEVICE_PUSH_KIT_REGISTERED_EVENT = 'pushKitRegistered'; export const DEVICE_PUSH_KIT_REGISTERED_EVENT = 'pushKitRegistered';
export const DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT = 'notificationReceivedForeground'; export const DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT = 'notificationReceivedForeground';
export const DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT = 'notificationReceivedBackground';
export const DEVICE_NOTIFICATION_OPENED_EVENT = 'notificationOpened'; export const DEVICE_NOTIFICATION_OPENED_EVENT = 'notificationOpened';
const DEVICE_NOTIFICATION_ACTION_RECEIVED = 'notificationActionReceived';
const _exportedEvents = [ const _exportedEvents = [
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT, DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT,
DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT, DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT,
DEVICE_PUSH_KIT_REGISTERED_EVENT, DEVICE_PUSH_KIT_REGISTERED_EVENT,
DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT, DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT,
DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT,
DEVICE_NOTIFICATION_OPENED_EVENT DEVICE_NOTIFICATION_OPENED_EVENT
]; ];
const _notificationHandlers = new Map(); const _notificationHandlers = new Map();
const _actionHandlers = new Map(); const _actionHandlers = new Map();
let _actionListener;
export class NotificationAction { export class NotificationAction {
options: Object; options: Object;
handler: Function;
constructor(options: Object, handler: Function) { constructor(options: Object) {
this.options = options; this.options = options;
this.handler = handler;
} }
} }
...@@ -56,7 +49,6 @@ export default class NotificationsIOS { ...@@ -56,7 +49,6 @@ export default class NotificationsIOS {
* *
* - `remoteNotificationsRegistered` : Fired when the user registers for remote notifications. The handler will be invoked with a hex string representing the deviceToken. * - `remoteNotificationsRegistered` : Fired when the user registers for remote notifications. The handler will be invoked with a hex string representing the deviceToken.
* - `notificationReceivedForeground` : Fired when a notification (local / remote) is received when app is on foreground state. * - `notificationReceivedForeground` : Fired when a notification (local / remote) is received when app is on foreground state.
* - `notificationReceivedBackground`: Fired when a background notification is received.
* - `notificationOpened`: Fired when a notification (local / remote) is opened. * - `notificationOpened`: Fired when a notification (local / remote) is opened.
*/ */
static addEventListener(type: string, handler: Function) { static addEventListener(type: string, handler: Function) {
...@@ -78,13 +70,20 @@ export default class NotificationsIOS { ...@@ -78,13 +70,20 @@ export default class NotificationsIOS {
DEVICE_PUSH_KIT_REGISTERED_EVENT, DEVICE_PUSH_KIT_REGISTERED_EVENT,
registration => handler(registration.pushKitToken) registration => handler(registration.pushKitToken)
); );
} else { } else if (type === DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT) {
listener = DeviceEventEmitter.addListener( listener = DeviceEventEmitter.addListener(
type, type,
({payload, identifier}) => handler(new IOSNotification(payload), (presentingOptions) => { ({payload, identifier}) => handler(new IOSNotification(payload), (presentingOptions) => {
NativeRNNotifications.finishPresentingNotification(identifier, presentingOptions); NativeRNNotifications.finishPresentingNotification(identifier, presentingOptions);
}) })
); );
} else if (type === DEVICE_NOTIFICATION_OPENED_EVENT) {
listener = DeviceEventEmitter.addListener(
type,
({payload, identifier, action}) => handler(new IOSNotification(payload), () => {
NativeRNNotifications.finishHandlingAction(identifier);
}, action)
);
} }
_notificationHandlers.set(handler, listener); _notificationHandlers.set(handler, listener);
...@@ -125,9 +124,6 @@ export default class NotificationsIOS { ...@@ -125,9 +124,6 @@ export default class NotificationsIOS {
let notificationCategories = []; let notificationCategories = [];
if (categories) { if (categories) {
// subscribe once for all actions
_actionListener = NativeAppEventEmitter.addListener(DEVICE_NOTIFICATION_ACTION_RECEIVED, this._actionHandlerDispatcher.bind(this));
notificationCategories = categories.map(category => { notificationCategories = categories.map(category => {
return Object.assign({}, category.options, { return Object.assign({}, category.options, {
actions: category.options.actions.map(action => { actions: category.options.actions.map(action => {
...@@ -155,10 +151,6 @@ export default class NotificationsIOS { ...@@ -155,10 +151,6 @@ export default class NotificationsIOS {
* memory leaks * memory leaks
*/ */
static resetCategories() { static resetCategories() {
if (_actionListener) {
_actionListener.remove();
}
_actionHandlers.clear(); _actionHandlers.clear();
} }
...@@ -200,10 +192,10 @@ export default class NotificationsIOS { ...@@ -200,10 +192,10 @@ export default class NotificationsIOS {
* *
* notification is an object containing: * notification is an object containing:
* *
* - `alertBody` : The message displayed in the notification alert. * - `body` : The message displayed in the notification alert.
* - `alertTitle` : The message title displayed in the notification. * - `title` : The message title displayed in the notification.
* - `alertAction` : The 'action' displayed beneath an actionable notification. Defaults to 'view'; * - `alertAction` : The 'action' displayed beneath an actionable notification. Defaults to 'view';
* - `soundName` : The sound played when the notification is fired (optional). * - `sound` : The sound played when the notification is fired (optional).
* - `silent` : If true, the notification sound will be suppressed (optional). * - `silent` : If true, the notification sound will be suppressed (optional).
* - `category` : The category of this notification, required for actionable notifications (optional). * - `category` : The category of this notification, required for actionable notifications (optional).
* - `userInfo` : An optional object containing additional notification data. * - `userInfo` : An optional object containing additional notification data.
...@@ -256,8 +248,8 @@ export default class NotificationsIOS { ...@@ -256,8 +248,8 @@ export default class NotificationsIOS {
* A delivered notification is an object containing: * A delivered notification is an object containing:
* *
* - `identifier` : The identifier of this notification. * - `identifier` : The identifier of this notification.
* - `alertBody` : The message displayed in the notification alert. * - `body` : The message displayed in the notification alert.
* - `alertTitle` : The message title displayed in the notification. * - `title` : The message title displayed in the notification.
* - `category` : The category of this notification, if has one. * - `category` : The category of this notification, if has one.
* - `userInfo` : An optional object containing additional notification data. * - `userInfo` : An optional object containing additional notification data.
* - `thread-id` : The thread identifier of this notification, if has one. * - `thread-id` : The thread identifier of this notification, if has one.
......
...@@ -218,10 +218,10 @@ describe('NotificationsIOS', () => { ...@@ -218,10 +218,10 @@ describe('NotificationsIOS', () => {
it('should call native local notification method with generated notification guid and notification object', () => { it('should call native local notification method with generated notification guid and notification object', () => {
let someLocalNotification = { let someLocalNotification = {
alertBody: 'some body', body: 'some body',
alertTitle: 'some title', title: 'some title',
alertAction: 'some action', alertAction: 'some action',
soundName: 'sound', sound: 'sound',
category: 'SOME_CATEGORY', category: 'SOME_CATEGORY',
userInfo: { userInfo: {
'key': 'value' 'key': 'value'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment