mirror of
https://github.com/zhigang1992/react-native-notifications.git
synced 2026-06-10 07:19:38 +08:00
Merge remote-tracking branch 'origin' into v3
This commit is contained in:
@@ -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.*
|
||||
|
||||
|
||||
10
RNNotifications/RNNotificationCenterMulticast.h
Normal file
10
RNNotifications/RNNotificationCenterMulticast.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
|
||||
@interface RNNotificationCenterMulticast : NSObject<UNUserNotificationCenterDelegate>
|
||||
|
||||
- (void)addNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate;
|
||||
- (void)removeNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
52
RNNotifications/RNNotificationCenterMulticast.m
Normal file
52
RNNotifications/RNNotificationCenterMulticast.m
Normal file
@@ -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<UNUserNotificationCenterDelegate>)delegate {
|
||||
[delegates addObject:delegate];
|
||||
}
|
||||
|
||||
- (void)removeNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate {
|
||||
[delegates removeObject:delegate];
|
||||
}
|
||||
|
||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
|
||||
{
|
||||
for (id<UNUserNotificationCenterDelegate> 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<UNUserNotificationCenterDelegate> 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<UNUserNotificationCenterDelegate> delegate in delegates) {
|
||||
if ([delegate respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)]) {
|
||||
if (@available(iOS 12.0, *)) {
|
||||
[delegate userNotificationCenter:center openSettingsForNotification:notification];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -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.
|
||||
**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
|
||||
+<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable notification_icon" />
|
||||
```
|
||||
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -10,8 +10,6 @@
|
||||
android:name="${applicationId}.permission.C2D_MESSAGE"
|
||||
android:protectionLevel="signature" />
|
||||
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
|
||||
|
||||
<!-- Ref: http://stackoverflow.com/questions/13602190/java-lang-securityexception-requires-vibrate-permission-on-jelly-bean-4-2 -->
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<application>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -9,4 +9,6 @@ public interface IPushNotificationsDrawer {
|
||||
|
||||
void onNotificationOpened();
|
||||
void onNotificationClearRequest(int id);
|
||||
void onNotificationClearRequest(String tag, int id);
|
||||
void onAllNotificationsClearRequest();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
- (instancetype)initWithNotificationEventHandler:(RNNotificationEventHandler *)notificationEventHandler {
|
||||
self = [super init];
|
||||
_notificationEventHandler = notificationEventHandler;
|
||||
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -12,4 +12,7 @@
|
||||
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken;
|
||||
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
|
||||
|
||||
+ (void)addNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate;
|
||||
+ (void)removeNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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<UNUserNotificationCenterDelegate>)delegate {
|
||||
[[self sharedInstance] addNativeDelegate:delegate];
|
||||
}
|
||||
|
||||
+ (void)removeNativeDelegate:(id<UNUserNotificationCenterDelegate>)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<UNUserNotificationCenterDelegate>)delegate {
|
||||
[_notificationCenterMulticast addNativeDelegate:delegate];
|
||||
}
|
||||
|
||||
- (void)removeNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate {
|
||||
[_notificationCenterMulticast removeNativeDelegate:delegate];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -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 = "<group>"; };
|
||||
3000AE3F23857F1D00DD26E9 /* RNNotificationCenterMulticast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNotificationCenterMulticast.h; sourceTree = "<group>"; };
|
||||
50002A4C22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNCommandsHandlerIntegrationTest.m; sourceTree = "<group>"; };
|
||||
50002A7F22E8885A008F6742 /* libOCMock.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libOCMock.a; sourceTree = "<group>"; };
|
||||
50002AC722E9D5EA008F6742 /* RNNotificationsStoreTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNotificationsStoreTests.m; sourceTree = "<group>"; };
|
||||
@@ -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 */,
|
||||
|
||||
Reference in New Issue
Block a user