diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index 9d133f0..338ef29 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,30 @@ # Changelog +## 2.1.7 (14/12/2019) +*No changelog for this release.* + +--- + +## 2.1.6 (20/11/2019) +*No changelog for this release.* + +--- + +## 2.1.5 (28/10/2019) +*No changelog for this release.* + +--- + +## 2.1.4 (27/10/2019) +*No changelog for this release.* + +--- + +## 2.1.4-beta.0 (27/10/2019) +*No changelog for this release.* + +--- + ## 3.0.0-beta.1 (07/10/2019) *No changelog for this release.* diff --git a/RNNotifications/RNNotificationCenterMulticast.h b/RNNotifications/RNNotificationCenterMulticast.h new file mode 100644 index 0000000..eed6797 --- /dev/null +++ b/RNNotifications/RNNotificationCenterMulticast.h @@ -0,0 +1,10 @@ +#import +#import + +@interface RNNotificationCenterMulticast : NSObject + +- (void)addNativeDelegate:(id)delegate; +- (void)removeNativeDelegate:(id)delegate; + +@end + diff --git a/RNNotifications/RNNotificationCenterMulticast.m b/RNNotifications/RNNotificationCenterMulticast.m new file mode 100644 index 0000000..c1c6add --- /dev/null +++ b/RNNotifications/RNNotificationCenterMulticast.m @@ -0,0 +1,52 @@ +#import "RNNotificationCenterMulticast.h" + +@implementation RNNotificationCenterMulticast { + NSHashTable *delegates; +} + +- (id)init { + self = [super init]; + if (self) { + delegates = [NSHashTable weakObjectsHashTable]; + } + return self; +} + +- (void)addNativeDelegate:(id)delegate { + [delegates addObject:delegate]; +} + +- (void)removeNativeDelegate:(id)delegate { + [delegates removeObject:delegate]; +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler +{ + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)]) { + [delegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; + } + } +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler +{ + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) { + [delegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; + } + } +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(nullable UNNotification *)notification +{ + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)]) { + if (@available(iOS 12.0, *)) { + [delegate userNotificationCenter:center openSettingsForNotification:notification]; + } + } + } +} + +@end diff --git a/docs_old/installation.md b/docs_old/installation.md index 56c52d2..bf476e4 100644 --- a/docs_old/installation.md +++ b/docs_old/installation.md @@ -183,4 +183,13 @@ To do so edit `android/build.gradle` and add: +} ``` -**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative59")`). This is why we recommend the first solution. \ No newline at end of file +**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative59")`). This is why we recommend the first solution. + +#### Step #6: Set your notification Icon. + +By default, the package will use your native application icon. If your icon is not notification friendly, you may have to set and use a different icon. To do this, create a notification_icon.png and add it to your drawable folders. Once that is done add the following line to your AndroidManifest.xml + +```diff ++ +``` + diff --git a/example/android/build.gradle b/example/android/build.gradle index 77dc62d..ba10e22 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -15,7 +15,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:3.5.3' classpath 'com.google.gms:google-services:4.0.1' } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 8cbe8db..6bc9331 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Nov 04 14:31:28 IST 2018 +#Thu Dec 12 22:59:18 IST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/lib/android/app/build.gradle b/lib/android/app/build.gradle index 2ff78bf..2cc44dc 100644 --- a/lib/android/app/build.gradle +++ b/lib/android/app/build.gradle @@ -1,7 +1,6 @@ import groovy.json.JsonSlurper apply plugin: 'com.android.library' -apply from: '../prepare-robolectric.gradle' String resolveFlavor() { def packageSlurper = new JsonSlurper() @@ -18,7 +17,7 @@ String resolveFlavor() { } android { - compileSdkVersion 27 + compileSdkVersion 28 buildToolsVersion '28.0.3' defaultConfig { @@ -56,6 +55,10 @@ android { } } } + + unitTests { + includeAndroidResources = true + } } flavorDimensions "RNNotifications.reactNativeVersion" @@ -83,8 +86,8 @@ dependencies { // tests testImplementation 'junit:junit:4.12' - testImplementation 'org.robolectric:robolectric:3.5.1' + testImplementation 'org.robolectric:robolectric:4.3' testImplementation 'org.assertj:assertj-core:3.8.0' testImplementation 'com.squareup.assertj:assertj-android:1.1.1' - testImplementation 'org.mockito:mockito-core:2.13.0' + testImplementation 'org.mockito:mockito-core:2.25.1' } diff --git a/lib/android/app/local.properties b/lib/android/app/local.properties deleted file mode 100644 index 8891df9..0000000 --- a/lib/android/app/local.properties +++ /dev/null @@ -1,8 +0,0 @@ -## This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Wed Jan 30 11:37:18 IST 2019 -sdk.dir=/Users/yogevbd/android-sdk-macosx diff --git a/lib/android/app/src/main/AndroidManifest.xml b/lib/android/app/src/main/AndroidManifest.xml index 1ae59f8..7053040 100644 --- a/lib/android/app/src/main/AndroidManifest.xml +++ b/lib/android/app/src/main/AndroidManifest.xml @@ -10,8 +10,6 @@ android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> - - 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 9e235a3..c6c45f2 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 @@ -108,7 +108,12 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements @ReactMethod public void setCategories(ReadableArray categories) { - + + } + + public void cancelDeliveredNotification(String tag, int notificationId) { + IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + notificationsDrawer.onNotificationClearRequest(tag, notificationId); } @ReactMethod @@ -117,6 +122,11 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements promise.resolve(new Boolean(hasPermission)); } + @ReactMethod void removeAllDeliveredNotifications() { + IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + notificationsDrawer.onAllNotificationsClearRequest(); + } + protected void startFcmIntentService(String extraFlag) { final Context appContext = getReactApplicationContext().getApplicationContext(); final Intent tokenFetchIntent = new Intent(appContext, FcmInstanceIdRefreshHandlerService.class); diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java index 3be3dc1..e22cd62 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java @@ -9,4 +9,6 @@ public interface IPushNotificationsDrawer { void onNotificationOpened(); void onNotificationClearRequest(int id); + void onNotificationClearRequest(String tag, int id); + void onAllNotificationsClearRequest(); } diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java index 7b320e1..dea6958 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java @@ -60,6 +60,18 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer { notificationManager.cancel(id); } + @Override + public void onNotificationClearRequest(String tag, int id) { + final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(tag, id); + } + + @Override + public void onAllNotificationsClearRequest() { + final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancelAll(); + } + protected void clearAll() { final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); diff --git a/lib/android/build.gradle b/lib/android/build.gradle index 0973eab..ec02bf7 100644 --- a/lib/android/build.gradle +++ b/lib/android/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.5.2' classpath 'com.google.gms:google-services:4.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/lib/android/gradle/wrapper/gradle-wrapper.properties b/lib/android/gradle/wrapper/gradle-wrapper.properties index 297208b..5108c78 100644 --- a/lib/android/gradle/wrapper/gradle-wrapper.properties +++ b/lib/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jan 04 11:01:32 EET 2018 +#Thu Dec 12 22:41:40 IST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/lib/android/prepare-robolectric.gradle b/lib/android/prepare-robolectric.gradle deleted file mode 100644 index 7570b17..0000000 --- a/lib/android/prepare-robolectric.gradle +++ /dev/null @@ -1,43 +0,0 @@ -def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.5.1-dependencies") - -configurations.create('robolectricRuntime') - -dependencies { - testImplementation "org.khronos:opengl-api:gl1.1-android-2.1_r1" - - robolectricRuntime "org.robolectric:android-all:8.1.0-robolectric-4402310" - - robolectricRuntime "org.robolectric:annotations:3.5.1" - robolectricRuntime "org.robolectric:junit:3.5.1" - robolectricRuntime "org.robolectric:resources:3.5.1" - robolectricRuntime "org.robolectric:sandbox:3.5.1" - robolectricRuntime "org.robolectric:utils:3.5.1" - robolectricRuntime "org.robolectric:shadows-framework:3.5.1" -} - -rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") { - println "downloadRobolectricDependencies into " + robolectricDependenciesFolder - from configurations.robolectricRuntime - into robolectricDependenciesFolder -} - -project.afterEvaluate { - tasks.all { - if (it.name.startsWith("test")) { - it.dependsOn(rootProject.tasks.findByName("downloadRobolectricDependencies")) - } - } -} - -android { - testOptions { - unitTests { - includeAndroidResources = true - } - unitTests.all { - systemProperty 'robolectric.offline', 'true' - systemProperty 'robolectric.dependency.dir', robolectricDependenciesFolder - } - } -} - diff --git a/lib/ios/RNNotificationCenterListener.m b/lib/ios/RNNotificationCenterListener.m index 97243b2..5c35ef2 100644 --- a/lib/ios/RNNotificationCenterListener.m +++ b/lib/ios/RNNotificationCenterListener.m @@ -8,7 +8,6 @@ - (instancetype)initWithNotificationEventHandler:(RNNotificationEventHandler *)notificationEventHandler { self = [super init]; _notificationEventHandler = notificationEventHandler; - [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; return self; } diff --git a/lib/ios/RNNotifications.h b/lib/ios/RNNotifications.h index 2e27739..5e0a093 100644 --- a/lib/ios/RNNotifications.h +++ b/lib/ios/RNNotifications.h @@ -12,4 +12,7 @@ + (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken; + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; ++ (void)addNativeDelegate:(id)delegate; ++ (void)removeNativeDelegate:(id)delegate; + @end diff --git a/lib/ios/RNNotifications.m b/lib/ios/RNNotifications.m index 501410b..9404319 100644 --- a/lib/ios/RNNotifications.m +++ b/lib/ios/RNNotifications.m @@ -4,6 +4,7 @@ #import "RNNotifications.h" #import "RNNotificationCenterListener.h" #import "RNPushKit.h" +#import "RNNotificationCenterMulticast.h" @implementation RNNotifications { RNPushKit* _pushKit; @@ -11,6 +12,7 @@ RNNotificationEventHandler* _notificationEventHandler; RNPushKitEventHandler* _pushKitEventHandler; RNEventEmitter* _eventEmitter; + RNNotificationCenterMulticast* _notificationCenterMulticast; } - (instancetype)init { @@ -45,8 +47,21 @@ [[self sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error]; } ++ (void)addNativeDelegate:(id)delegate { + [[self sharedInstance] addNativeDelegate:delegate]; +} + ++ (void)removeNativeDelegate:(id)delegate { + [[self sharedInstance] removeNativeDelegate:delegate]; +} + - (void)startMonitorNotifications { _notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler]; + + _notificationCenterMulticast = [[RNNotificationCenterMulticast alloc] init]; + [[UNUserNotificationCenter currentNotificationCenter] setDelegate:_notificationCenterMulticast]; + + [_notificationCenterMulticast addNativeDelegate:_notificationCenterListener]; } - (void)startMonitorPushKitNotifications { @@ -62,4 +77,12 @@ [_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error]; } +- (void)addNativeDelegate:(id)delegate { + [_notificationCenterMulticast addNativeDelegate:delegate]; +} + +- (void)removeNativeDelegate:(id)delegate { + [_notificationCenterMulticast removeNativeDelegate:delegate]; +} + @end diff --git a/lib/ios/RNNotifications.xcodeproj/project.pbxproj b/lib/ios/RNNotifications.xcodeproj/project.pbxproj index fe2bba1..c62a9d4 100644 --- a/lib/ios/RNNotifications.xcodeproj/project.pbxproj +++ b/lib/ios/RNNotifications.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 3000AE4023857F1D00DD26E9 /* RNNotificationCenterMulticast.m in Sources */ = {isa = PBXBuildFile; fileRef = 3000AE3E23857F1C00DD26E9 /* RNNotificationCenterMulticast.m */; }; + 3000AE4123857F1D00DD26E9 /* RNNotificationCenterMulticast.h in Headers */ = {isa = PBXBuildFile; fileRef = 3000AE3F23857F1D00DD26E9 /* RNNotificationCenterMulticast.h */; }; 50002A4D22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50002A4C22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m */; }; 50002A8022E8885A008F6742 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 50002A7F22E8885A008F6742 /* libOCMock.a */; }; 50002AC822E9D5EA008F6742 /* RNNotificationsStoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 50002AC722E9D5EA008F6742 /* RNNotificationsStoreTests.m */; }; @@ -82,6 +84,8 @@ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libRNNotifications.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNNotifications.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 3000AE3E23857F1C00DD26E9 /* RNNotificationCenterMulticast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNotificationCenterMulticast.m; sourceTree = ""; }; + 3000AE3F23857F1D00DD26E9 /* RNNotificationCenterMulticast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNotificationCenterMulticast.h; sourceTree = ""; }; 50002A4C22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNCommandsHandlerIntegrationTest.m; sourceTree = ""; }; 50002A7F22E8885A008F6742 /* libOCMock.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libOCMock.a; sourceTree = ""; }; 50002AC722E9D5EA008F6742 /* RNNotificationsStoreTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNotificationsStoreTests.m; sourceTree = ""; }; @@ -286,6 +290,8 @@ 508CE81F22D1371700357815 /* Helpers */ = { isa = PBXGroup; children = ( + 3000AE3F23857F1D00DD26E9 /* RNNotificationCenterMulticast.h */, + 3000AE3E23857F1C00DD26E9 /* RNNotificationCenterMulticast.m */, 508CE82022D1372E00357815 /* RNNotificationUtils.h */, 508CE82122D1372E00357815 /* RNNotificationUtils.m */, 50351F9322CD7FF1000713B3 /* RCTConvert+RNNotifications.h */, @@ -333,6 +339,7 @@ 508CE81D22D1337200357815 /* RNPushKit.h in Headers */, 50AD1FCA22D13ADB00E12362 /* RNPushKitEventHandler.h in Headers */, 508CE7D522D12CCA00357815 /* RNNotificationEventHandler.h in Headers */, + 3000AE4123857F1D00DD26E9 /* RNNotificationCenterMulticast.h in Headers */, 50FED76622D3E06500DDD516 /* RNNotificationCenter.h in Headers */, 508CE81922D130B900357815 /* RNPushKitEventListener.h in Headers */, 50E49F0722D1E4E0007160C1 /* RNNotificationsStore.h in Headers */, @@ -409,6 +416,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 58B511D21A9E6C8500147676; @@ -452,6 +460,7 @@ 50351F9822CD8604000713B3 /* RNCommandsHandler.m in Sources */, D8A2F7551CB57F1A002CC8F5 /* RNNotifications.m in Sources */, 50351F8F22CD782F000713B3 /* RNEventEmitter.m in Sources */, + 3000AE4023857F1D00DD26E9 /* RNNotificationCenterMulticast.m in Sources */, 508CE81A22D130B900357815 /* RNPushKitEventListener.m in Sources */, 50351F9222CD7DF4000713B3 /* RNBridgeModule.m in Sources */, 50FED76722D3E06500DDD516 /* RNNotificationCenter.m in Sources */,