From 3a6e12306f694de7f58c6f9fe68d68ca092b47d5 Mon Sep 17 00:00:00 2001 From: James Holcomb Date: Tue, 27 Jul 2021 10:12:15 -0500 Subject: [PATCH 1/9] feat: perform iOS actions when app in dead state --- .../RNNotificationsModule.java | 5 +++++ lib/ios/RNBridgeModule.m | 4 ++++ lib/ios/RNNotificationEventHandler.m | 1 + lib/ios/RNNotificationsStore.h | 2 ++ lib/ios/RNNotificationsStore.m | 9 +++++++++ lib/src/Notifications.ts | 7 +++++++ lib/src/adapters/NativeCommandsSender.ts | 5 +++++ lib/src/commands/Commands.ts | 10 ++++++++++ 8 files changed, 43 insertions(+) diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index db9eabaa4..203ffa52a 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -113,6 +113,11 @@ public void cancelLocalNotification(int notificationId) { public void setCategories(ReadableArray categories) { } + + @ReactMethod + public void getLastAction(Promise promise) { + promise.resolve(); + } public void cancelDeliveredNotification(String tag, int notificationId) { IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); diff --git a/lib/ios/RNBridgeModule.m b/lib/ios/RNBridgeModule.m index 2526f5836..c25c04906 100644 --- a/lib/ios/RNBridgeModule.m +++ b/lib/ios/RNBridgeModule.m @@ -97,6 +97,10 @@ - (dispatch_queue_t)methodQueue { [_commandsHandler checkPermissions:resolve reject:reject]; } +RCT_EXPORT_METHOD(getLastAction: (RCTPromiseResolveBlock) resolve reject: (RCTPromiseRejectBlock)reject){ + resolve([[RNNotificationsStore sharedInstance] getLastAction]); +} + #if !TARGET_OS_TV RCT_EXPORT_METHOD(removeAllDeliveredNotifications) { diff --git a/lib/ios/RNNotificationEventHandler.m b/lib/ios/RNNotificationEventHandler.m index 5c8dd0b35..3e089f7ba 100644 --- a/lib/ios/RNNotificationEventHandler.m +++ b/lib/ios/RNNotificationEventHandler.m @@ -30,6 +30,7 @@ - (void)didReceiveForegroundNotification:(UNNotification *)notification withComp - (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(void))completionHandler { [_store setActionCompletionHandler:completionHandler withCompletionKey:response.notification.request.identifier]; + [_store setLastAction:[RNNotificationParser parseNotificationResponse:response]]; [RNEventEmitter sendEvent:RNNotificationOpened body:[RNNotificationParser parseNotificationResponse:response]]; } diff --git a/lib/ios/RNNotificationsStore.h b/lib/ios/RNNotificationsStore.h index 4f8a17199..430ece0aa 100644 --- a/lib/ios/RNNotificationsStore.h +++ b/lib/ios/RNNotificationsStore.h @@ -14,6 +14,8 @@ - (void)setActionCompletionHandler:(void (^)(void))completionHandler withCompletionKey:(NSString *)completionKey; - (void)setPresentationCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler withCompletionKey:(NSString *)completionKey; - (void)setBackgroundActionCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler withCompletionKey:(NSString *)completionKey; +- (void)setLastAction:(NSDictionary*)lastAction; +- (NSDictionary *)getLastAction; - (void (^)(void))getActionCompletionHandler:(NSString *)key; - (void (^)(UNNotificationPresentationOptions))getPresentationCompletionHandler:(NSString *)key; diff --git a/lib/ios/RNNotificationsStore.m b/lib/ios/RNNotificationsStore.m index bcc9abc85..c71000047 100644 --- a/lib/ios/RNNotificationsStore.m +++ b/lib/ios/RNNotificationsStore.m @@ -4,6 +4,7 @@ @implementation RNNotificationsStore NSMutableDictionary* _actionCompletionHandlers; NSMutableDictionary* _presentationCompletionHandlers; NSMutableDictionary* _backgroundActionCompletionHandlers; +NSDictionary* _lastAction; + (instancetype)sharedInstance { static RNNotificationsStore *sharedInstance = nil; @@ -73,4 +74,12 @@ - (void)completeBackgroundAction:(NSString *)completionKey withBackgroundFetchRe } } +- (void)setLastAction:(NSDictionary*)lastAction{ + _lastAction = lastAction; +} + +- (NSDictionary *)getLastAction{ + return _lastAction; +} + @end diff --git a/lib/src/Notifications.ts b/lib/src/Notifications.ts index 0848f6d4a..789d6538f 100644 --- a/lib/src/Notifications.ts +++ b/lib/src/Notifications.ts @@ -73,6 +73,13 @@ export class NotificationsRoot { this.commands.setCategories(categories); } + /** + * getLastAction + */ + public getLastAction(): Promise { + return this.commands.getLastAction(); + } + /** * cancelLocalNotification */ diff --git a/lib/src/adapters/NativeCommandsSender.ts b/lib/src/adapters/NativeCommandsSender.ts index 33a9508fb..4221d5da5 100644 --- a/lib/src/adapters/NativeCommandsSender.ts +++ b/lib/src/adapters/NativeCommandsSender.ts @@ -8,6 +8,7 @@ import { NotificationPermissionOptions } from '../interfaces/NotificationPermiss interface NativeCommandsModule { getInitialNotification(): Promise; + getLastAction(): Promise; postLocalNotification(notification: Notification, id: number): void; requestPermissions(options: NotificationPermissionOptions): void; abandonPermissions(): void; @@ -63,6 +64,10 @@ export class NativeCommandsSender { this.nativeCommandsModule.setCategories(categories); } + getLastAction(): Promise { + return this.nativeCommandsModule.getLastAction(); + } + getBadgeCount(): Promise { return this.nativeCommandsModule.getBadgeCount(); } diff --git a/lib/src/commands/Commands.ts b/lib/src/commands/Commands.ts index 1f344457c..75a0bebc0 100644 --- a/lib/src/commands/Commands.ts +++ b/lib/src/commands/Commands.ts @@ -48,6 +48,16 @@ export class Commands { this.nativeCommandsSender.setCategories(categories); } + public async getLastAction(): Promise { + return this.nativeCommandsSender.getLastAction().then((payload) => { + if (payload) { + return this.notificationFactory.fromPayload(payload); + } + + return undefined; + }) + } + public getBadgeCount(): Promise { return this.nativeCommandsSender.getBadgeCount(); } From d43620fe52c9de716d010f1ed0b4471e359cd6d8 Mon Sep 17 00:00:00 2001 From: James Holcomb Date: Tue, 27 Jul 2021 10:31:55 -0500 Subject: [PATCH 2/9] 4.1.2-rc.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e962c9258..cc5a04685 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "4.1.1", + "version": "4.1.2-rc.0", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", @@ -134,4 +134,4 @@ "html" ] } -} \ No newline at end of file +} From 2804d5be3712cc5d3497210726d2a66333878734 Mon Sep 17 00:00:00 2001 From: James Holcomb Date: Tue, 27 Jul 2021 11:21:12 -0500 Subject: [PATCH 3/9] fix: promise must resolve(null) --- .../com/wix/reactnativenotifications/RNNotificationsModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index 203ffa52a..c6c331d9c 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -116,7 +116,7 @@ public void setCategories(ReadableArray categories) { @ReactMethod public void getLastAction(Promise promise) { - promise.resolve(); + promise.resolve(null); } public void cancelDeliveredNotification(String tag, int notificationId) { From beb20dab7c7093d3f4f0ace636599c8e6638db71 Mon Sep 17 00:00:00 2001 From: James Holcomb Date: Thu, 29 Jul 2021 11:46:18 -0500 Subject: [PATCH 4/9] fix: lastAction => initialAction get performs destructive read --- .../RNNotificationsModule.java | 10 +-- lib/ios/RNBridgeModule.m | 8 +-- lib/ios/RNCommandsHandler.h | 2 + lib/ios/RNCommandsHandler.m | 8 +++ lib/ios/RNNotificationEventHandler.m | 2 +- lib/ios/RNNotificationsStore.h | 3 +- lib/ios/RNNotificationsStore.m | 9 --- lib/src/Notifications.ts | 14 ++-- lib/src/adapters/NativeCommandsSender.ts | 11 ++-- lib/src/commands/Commands.test.ts | 65 +++++++++++++++---- lib/src/commands/Commands.ts | 20 +++--- 11 files changed, 97 insertions(+), 55 deletions(-) diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index c6c331d9c..19beab99b 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -95,6 +95,11 @@ public void getInitialNotification(final Promise promise) { } } + @ReactMethod + public void getInitialAction(final Promise promise) { + promise.resolve(null); + } + @ReactMethod public void postLocalNotification(ReadableMap notificationPropsMap, int notificationId) { if(BuildConfig.DEBUG) Log.d(LOGTAG, "Native method invocation: postLocalNotification"); @@ -113,11 +118,6 @@ public void cancelLocalNotification(int notificationId) { public void setCategories(ReadableArray categories) { } - - @ReactMethod - public void getLastAction(Promise promise) { - promise.resolve(null); - } public void cancelDeliveredNotification(String tag, int notificationId) { IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); diff --git a/lib/ios/RNBridgeModule.m b/lib/ios/RNBridgeModule.m index c25c04906..7e83dca8f 100644 --- a/lib/ios/RNBridgeModule.m +++ b/lib/ios/RNBridgeModule.m @@ -48,6 +48,10 @@ - (dispatch_queue_t)methodQueue { [_commandsHandler getInitialNotification:resolve reject:reject]; } +RCT_EXPORT_METHOD(getInitialAction: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject){ + [_commandsHandler getInitialAction:resolve reject:reject]; +} + RCT_EXPORT_METHOD(finishHandlingAction:(NSString *)completionKey) { [_commandsHandler finishHandlingAction:completionKey]; } @@ -97,10 +101,6 @@ - (dispatch_queue_t)methodQueue { [_commandsHandler checkPermissions:resolve reject:reject]; } -RCT_EXPORT_METHOD(getLastAction: (RCTPromiseResolveBlock) resolve reject: (RCTPromiseRejectBlock)reject){ - resolve([[RNNotificationsStore sharedInstance] getLastAction]); -} - #if !TARGET_OS_TV RCT_EXPORT_METHOD(removeAllDeliveredNotifications) { diff --git a/lib/ios/RNCommandsHandler.h b/lib/ios/RNCommandsHandler.h index b7e10e4f4..790aca5da 100644 --- a/lib/ios/RNCommandsHandler.h +++ b/lib/ios/RNCommandsHandler.h @@ -11,6 +11,8 @@ - (void)getInitialNotification:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject; +- (void)getInitialAction:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject; + - (void)finishHandlingAction:(NSString *)completionKey; - (void)finishPresentingNotification:(NSString *)completionKey presentingOptions:(NSDictionary *)presentingOptions; diff --git a/lib/ios/RNCommandsHandler.m b/lib/ios/RNCommandsHandler.m index 55049299e..10abb78b8 100644 --- a/lib/ios/RNCommandsHandler.m +++ b/lib/ios/RNCommandsHandler.m @@ -27,6 +27,14 @@ - (void)getInitialNotification:(RCTPromiseResolveBlock)resolve reject:(RCTPromis resolve(initialNotification); } + +- (void)getInitialAction:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { + NSDictionary* initialAction = [[RNNotificationsStore sharedInstance] initialAction]; + [[RNNotificationsStore sharedInstance] setInitialAction:nil]; + resolve(initialAction); +} + + - (void)finishHandlingAction:(NSString *)completionKey { [[RNNotificationsStore sharedInstance] completeAction:completionKey]; } diff --git a/lib/ios/RNNotificationEventHandler.m b/lib/ios/RNNotificationEventHandler.m index 3e089f7ba..ea67b52ef 100644 --- a/lib/ios/RNNotificationEventHandler.m +++ b/lib/ios/RNNotificationEventHandler.m @@ -30,7 +30,7 @@ - (void)didReceiveForegroundNotification:(UNNotification *)notification withComp - (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(void))completionHandler { [_store setActionCompletionHandler:completionHandler withCompletionKey:response.notification.request.identifier]; - [_store setLastAction:[RNNotificationParser parseNotificationResponse:response]]; + [_store setInitialAction:[RNNotificationParser parseNotificationResponse:response]]; [RNEventEmitter sendEvent:RNNotificationOpened body:[RNNotificationParser parseNotificationResponse:response]]; } diff --git a/lib/ios/RNNotificationsStore.h b/lib/ios/RNNotificationsStore.h index 430ece0aa..4b06dbf49 100644 --- a/lib/ios/RNNotificationsStore.h +++ b/lib/ios/RNNotificationsStore.h @@ -5,6 +5,7 @@ @interface RNNotificationsStore : NSObject @property (nonatomic, retain) NSDictionary* initialNotification; +@property (nonatomic, retain) NSDictionary* initialAction; + (instancetype)sharedInstance; @@ -14,8 +15,6 @@ - (void)setActionCompletionHandler:(void (^)(void))completionHandler withCompletionKey:(NSString *)completionKey; - (void)setPresentationCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler withCompletionKey:(NSString *)completionKey; - (void)setBackgroundActionCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler withCompletionKey:(NSString *)completionKey; -- (void)setLastAction:(NSDictionary*)lastAction; -- (NSDictionary *)getLastAction; - (void (^)(void))getActionCompletionHandler:(NSString *)key; - (void (^)(UNNotificationPresentationOptions))getPresentationCompletionHandler:(NSString *)key; diff --git a/lib/ios/RNNotificationsStore.m b/lib/ios/RNNotificationsStore.m index c71000047..bcc9abc85 100644 --- a/lib/ios/RNNotificationsStore.m +++ b/lib/ios/RNNotificationsStore.m @@ -4,7 +4,6 @@ @implementation RNNotificationsStore NSMutableDictionary* _actionCompletionHandlers; NSMutableDictionary* _presentationCompletionHandlers; NSMutableDictionary* _backgroundActionCompletionHandlers; -NSDictionary* _lastAction; + (instancetype)sharedInstance { static RNNotificationsStore *sharedInstance = nil; @@ -74,12 +73,4 @@ - (void)completeBackgroundAction:(NSString *)completionKey withBackgroundFetchRe } } -- (void)setLastAction:(NSDictionary*)lastAction{ - _lastAction = lastAction; -} - -- (NSDictionary *)getLastAction{ - return _lastAction; -} - @end diff --git a/lib/src/Notifications.ts b/lib/src/Notifications.ts index 789d6538f..18018e849 100644 --- a/lib/src/Notifications.ts +++ b/lib/src/Notifications.ts @@ -66,19 +66,19 @@ export class NotificationsRoot { return this.commands.getInitialNotification(); } + /** + * getInitialAction + */ + public getInitialAction(): Promise { + return this.commands.getInitialAction(); + } + /** * setCategories */ public setCategories(categories: [NotificationCategory?]) { this.commands.setCategories(categories); } - - /** - * getLastAction - */ - public getLastAction(): Promise { - return this.commands.getLastAction(); - } /** * cancelLocalNotification diff --git a/lib/src/adapters/NativeCommandsSender.ts b/lib/src/adapters/NativeCommandsSender.ts index 4221d5da5..c9463ed72 100644 --- a/lib/src/adapters/NativeCommandsSender.ts +++ b/lib/src/adapters/NativeCommandsSender.ts @@ -5,10 +5,11 @@ import { NotificationPermissions } from '../interfaces/NotificationPermissions'; import { NotificationCategory } from '../interfaces/NotificationCategory'; import { NotificationChannel } from '../interfaces/NotificationChannel'; import { NotificationPermissionOptions } from '../interfaces/NotificationPermissions'; +import { NotificationResponse } from '../interfaces/NotificationEvents'; interface NativeCommandsModule { getInitialNotification(): Promise; - getLastAction(): Promise; + getInitialAction(): Promise; postLocalNotification(notification: Notification, id: number): void; requestPermissions(options: NotificationPermissionOptions): void; abandonPermissions(): void; @@ -44,6 +45,10 @@ export class NativeCommandsSender { return this.nativeCommandsModule.getInitialNotification(); } + getInitialAction(): Promise { + return this.nativeCommandsModule.getInitialAction(); + } + requestPermissions(options?: NotificationPermissionOptions) { return this.nativeCommandsModule.requestPermissions(options || {}); } @@ -64,10 +69,6 @@ export class NativeCommandsSender { this.nativeCommandsModule.setCategories(categories); } - getLastAction(): Promise { - return this.nativeCommandsModule.getLastAction(); - } - getBadgeCount(): Promise { return this.nativeCommandsModule.getBadgeCount(); } diff --git a/lib/src/commands/Commands.test.ts b/lib/src/commands/Commands.test.ts index 7eb4372ad..0f644b018 100644 --- a/lib/src/commands/Commands.test.ts +++ b/lib/src/commands/Commands.test.ts @@ -7,9 +7,9 @@ import { UniqueIdProvider } from '../adapters/UniqueIdProvider'; import { NotificationCategory } from '../interfaces/NotificationCategory'; import { NotificationPermissions } from '../interfaces/NotificationPermissions'; import { NotificationFactory } from '../DTO/NotificationFactory'; -import {NotificationAndroid} from "../DTO/NotificationAndroid"; -import {Platform} from "react-native"; -import {NotificationIOS} from "../DTO/NotificationIOS"; +import { NotificationAndroid } from "../DTO/NotificationAndroid"; +import { Platform } from "react-native"; +import { NotificationIOS } from "../DTO/NotificationIOS"; describe('Commands', () => { let uut: Commands; @@ -37,9 +37,9 @@ describe('Commands', () => { it('Android - returns a promise with the initial notification', async () => { Platform.OS = 'android'; - const expectedNotification: Notification = new NotificationAndroid({'google.message_id': 'id'}); + const expectedNotification: Notification = new NotificationAndroid({ 'google.message_id': 'id' }); when(mockedNativeCommandsSender.getInitialNotification()).thenResolve( - {'google.message_id': 'id'} + { 'google.message_id': 'id' } ); const result = await uut.getInitialNotification(); expect(result).toEqual(expectedNotification); @@ -54,15 +54,56 @@ describe('Commands', () => { it('iOS - returns a promise with the initial notification', async () => { Platform.OS = 'ios'; - const expectedNotification: Notification = new NotificationIOS({identifier: 'id'}); + const expectedNotification: Notification = new NotificationIOS({ identifier: 'id' }); when(mockedNativeCommandsSender.getInitialNotification()).thenResolve( - {identifier: 'id'} + { identifier: 'id' } ); const result = await uut.getInitialNotification(); expect(result).toEqual(expectedNotification); }); }); + describe('getInitialAction', () => { + it('sends to native', () => { + uut.getInitialAction(); + verify(mockedNativeCommandsSender.getInitialAction()).called(); + }); + + it('Android - should return undefined initial action', async () => { + Platform.OS = 'android'; + when(mockedNativeCommandsSender.getInitialAction()).thenResolve(); + const actual = await uut.getInitialAction(); + expect(actual).toEqual(undefined); + }); + + it('iOS - should return undefined initial action', async () => { + Platform.OS = 'ios'; + when(mockedNativeCommandsSender.getInitialAction()).thenResolve(); + const actual = await uut.getInitialAction(); + expect(actual).toEqual(undefined); + }); + + it('iOS - returns a promise with the initial action', async () => { + Platform.OS = 'ios'; + const expectedNotification: Notification = new Notification({ + identifier: 'id', + payload: { + action: { + identifier: 'id', + text: 'text' + }, + body: 'body', + title: 'title' + } + }); + when(mockedNativeCommandsSender.getInitialAction()).thenResolve( + { identifier: 'id', notification: expectedNotification, action: { identifier: 'id', text: 'text'} } + ); + const actual = await uut.getInitialAction(); + expect(actual).toEqual(expectedNotification); + }); + }); + describe('requestPermissions', () => { it('sends to native', () => { const opts = {}; @@ -92,7 +133,7 @@ describe('Commands', () => { }); it('sends to native with categories', () => { - const category: NotificationCategory = {identifier: 'id', actions: []}; + const category: NotificationCategory = { identifier: 'id', actions: [] }; const categoriesArray: [NotificationCategory] = [category]; uut.setCategories(categoriesArray); verify(mockedNativeCommandsSender.setCategories(categoriesArray)).called(); @@ -108,26 +149,26 @@ describe('Commands', () => { describe('postLocalNotification', () => { it('sends to native', () => { - const notification: Notification = new Notification({identifier: 'id'}); + const notification: Notification = new Notification({ identifier: 'id' }); uut.postLocalNotification(notification); verify(mockedNativeCommandsSender.postLocalNotification(notification, anyNumber())).called(); }); it('generates unique identifier', () => { - const notification: Notification = new Notification({identifier: 'id'}); + const notification: Notification = new Notification({ identifier: 'id' }); uut.postLocalNotification(notification); verify(mockedNativeCommandsSender.postLocalNotification(notification, anyNumber())).called(); }); it('use passed notification id', () => { - const notification: Notification = new Notification({identifier: 'id'}); + const notification: Notification = new Notification({ identifier: 'id' }); const passedId: number = 2; uut.postLocalNotification(notification, passedId); verify(mockedNativeCommandsSender.postLocalNotification(notification, passedId)).called(); }); it('return notification id', () => { - const notification: Notification = new Notification({identifier: 'id'}); + const notification: Notification = new Notification({ identifier: 'id' }); const notificationId: number = 2; const response = uut.postLocalNotification(notification, notificationId); expect(response).toEqual(notificationId); diff --git a/lib/src/commands/Commands.ts b/lib/src/commands/Commands.ts index 75a0bebc0..80bd0f544 100644 --- a/lib/src/commands/Commands.ts +++ b/lib/src/commands/Commands.ts @@ -30,6 +30,16 @@ export class Commands { }); } + public async getInitialAction(): Promise { + return this.nativeCommandsSender.getInitialAction().then((payload) => { + if (payload) { + return this.notificationFactory.fromPayload(payload); + } + + return undefined; + }); + } + public requestPermissions(options?: NotificationPermissionOptions) { const result = this.nativeCommandsSender.requestPermissions(options); return result; @@ -48,16 +58,6 @@ export class Commands { this.nativeCommandsSender.setCategories(categories); } - public async getLastAction(): Promise { - return this.nativeCommandsSender.getLastAction().then((payload) => { - if (payload) { - return this.notificationFactory.fromPayload(payload); - } - - return undefined; - }) - } - public getBadgeCount(): Promise { return this.nativeCommandsSender.getBadgeCount(); } From 511a7053de0bc0eb6ddb3ae81efc5b790971908d Mon Sep 17 00:00:00 2001 From: James Holcomb Date: Wed, 8 Sep 2021 07:02:42 -0500 Subject: [PATCH 5/9] chore: back to 4.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc5a04685..c553c7474 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "4.1.2-rc.0", + "version": "4.1.1", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", From a2c1c813430b9280799ba339e4bd893aa32a9438 Mon Sep 17 00:00:00 2001 From: James Holcomb Date: Wed, 8 Sep 2021 07:04:40 -0500 Subject: [PATCH 6/9] feat: ios add permissions to check permissions (#762) (#1) * FEAT: ios add permissions to check permissions (#762) * Update package.json version to 4.1.2 and generate CHANGELOG.gren.md [ci skip] Co-authored-by: DanielEliraz Co-authored-by: wixmobile --- CHANGELOG.gren.md | 69 ++++++++++++++----- example/index.js | 7 ++ lib/ios/RNNotificationCenter.m | 2 + lib/src/commands/Commands.test.ts | 2 + lib/src/interfaces/NotificationPermissions.ts | 2 + package.json | 2 +- 6 files changed, 66 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index fe324aa75..b686546f7 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,13 @@ # Changelog +## 4.1.1 (21/07/2021) + +#### Enhancements: + +- resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) + +--- + ## 4.1.0 (14/07/2021) #### Enhancements: @@ -123,6 +131,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -159,10 +168,11 @@ --- -## 2.1.0 (31/12/1969) +## v1.4.0 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -199,10 +209,11 @@ --- -## v1.4.0 (31/12/1969) +## v1.1.17 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -239,10 +250,11 @@ --- -## v1.1.17 (31/12/1969) +## v1.1.12 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -279,10 +291,11 @@ --- -## v1.1.12 (31/12/1969) +## 4.1.2 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -319,10 +332,11 @@ --- -## 4.1.1 (31/12/1969) +## 3.0.0-beta.4 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -359,10 +373,11 @@ --- -## 3.0.0-beta.4 (31/12/1969) +## 3.0.0-beta.2 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -399,10 +414,11 @@ --- -## 3.0.0-beta.2 (31/12/1969) +## 3.0.0 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -439,10 +455,11 @@ --- -## 3.0.0 (31/12/1969) +## 3.0.0-beta.1 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -483,6 +500,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -519,10 +537,11 @@ --- -## 3.0.0-beta.1 (31/12/1969) +## 3.0.0-beta.0 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -559,10 +578,11 @@ --- -## 3.0.0-beta.0 (31/12/1969) +## 3.0.0-alpha.0 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -599,10 +619,11 @@ --- -## 3.0.0-alpha.0 (31/12/1969) +## 2.1.7 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -639,10 +660,11 @@ --- -## 2.1.7 (31/12/1969) +## 2.1.6 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -683,6 +705,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -719,10 +742,11 @@ --- -## 2.1.6 (31/12/1969) +## 2.1.5 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -759,10 +783,11 @@ --- -## 2.1.5 (31/12/1969) +## 2.1.4 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -799,10 +824,11 @@ --- -## 2.1.4 (31/12/1969) +## 2.1.4-beta.0 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -839,10 +865,11 @@ --- -## 2.1.4-beta.0 (31/12/1969) +## 2.1.3 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -879,10 +906,11 @@ --- -## 2.1.3 (31/12/1969) +## 2.1.0 (31/12/1969) #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -923,6 +951,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -963,6 +992,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -1003,6 +1033,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -1043,6 +1074,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -1083,6 +1115,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -1123,6 +1156,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) @@ -1163,6 +1197,7 @@ #### Enhancements: +- FEAT: ios add permissions to check permissions [#762](https://github.com/wix/react-native-notifications/pull/762) by [DanielEliraz](https://github.com/DanielEliraz) - resiter remote on provisional approve [#759](https://github.com/wix/react-native-notifications/pull/759) by [DanielEliraz](https://github.com/DanielEliraz) - expose provisional state [#756](https://github.com/wix/react-native-notifications/pull/756) by [DanielEliraz](https://github.com/DanielEliraz) - Add ability to request/check more iOS permissions [#752](https://github.com/wix/react-native-notifications/pull/752) by [DanielEliraz](https://github.com/DanielEliraz) diff --git a/example/index.js b/example/index.js index 3d097fbbf..94bd0e261 100644 --- a/example/index.js +++ b/example/index.js @@ -154,6 +154,12 @@ class NotificationsExampleApp extends Component { }); } + isRegistered() { + Notifications.isRegisteredForRemoteNotifications().then((registered) => { + console.warn(registered); + }); + } + render() { const notifications = this.state.notifications.map((notification, idx) => ( @@ -181,6 +187,7 @@ class NotificationsExampleApp extends Component { }