Commit 498dd34b authored by aboelbisher's avatar aboelbisher Committed by GitHub

[WIP] iOS deprecated API replacement (#295)

* IOS deprecated API replacement
parent 2e74b4d2
//
// NRNNManager.h
// NRNNOtifications
//
// Created by Muhammad Abed El Razek on 09/01/2019.
// Copyright © 2019 Wix. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>
#import <PushKit/PushKit.h>
@protocol RNNRerouterDelegate <NSObject>
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler;
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler;
- (void)handlePushKitRegistered:(NSDictionary *)notification;
@end
@interface RNNRouter : NSObject<UNUserNotificationCenterDelegate>
+ (nonnull instancetype)sharedInstance;
@property (nonatomic, weak) id <RNNRerouterDelegate> _Nullable delegate;
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nullable void (^)(UIBackgroundFetchResult))completionHandler;
- (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type;
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type;
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler;
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler;
@end
//
// NRNNManager.m
// NRNNOtifications
//
// Created by Muhammad Abed El Razek on 09/01/2019.
// Copyright © 2019 Wix. All rights reserved.
//
#import "RNNRouter.h"
#import "RNNotifications.h"
//RNNNotifications's router (delegater) ::: singleton which routes all the static, system functions delegate calls to RNNNotifications insatnce ; can't have and RNNNotifications instance from outside of it's class
@interface RNNRouter()
@property(nonatomic,strong) NSMutableArray* pendingDelegateCalls;
@end
@implementation RNNRouter
+ (nonnull instancetype)sharedInstance
{
static RNNRouter* sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [self new];
});
return sharedInstance;
}
- (instancetype)init
{
self = [super init];
if(self)
{
_pendingDelegateCalls = [NSMutableArray new];
}
return self;
}
- (void)setDelegate:(id<RNNRerouterDelegate,UNUserNotificationCenterDelegate>)delegate
{
_delegate = delegate;
while (self.pendingDelegateCalls.count > 0)
{
void(^block)(void) = _pendingDelegateCalls.lastObject;
block();
[_pendingDelegateCalls removeLastObject];
}
}
/*
______ ______ _ _
| ___ \ | ___ \ | | (_)
| |_/ /___ ______| |_/ /___ _ _| |_ _ _ __ __ _
| // _ \______| // _ \| | | | __| | '_ \ / _` |
| |\ \ __/ | |\ \ (_) | |_| | |_| | | | | (_| |
\_| \_\___| \_| \_\___/ \__,_|\__|_|_| |_|\__, |
__/ |
|___/
*/
/////////////////////////////////////////////////////////////////
#pragma mark static calls for RNNNotifications rerouting purpous functions
////////////////////////////////////////////////////////////////
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
void(^callLaterBlock)(void) = ^{
[self->_delegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
};
if(_delegate)
{
callLaterBlock();
}
else // //called and _delegate is not set yet, need to store to call later
{
[_pendingDelegateCalls insertObject:callLaterBlock atIndex:0];
}
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
void(^callLaterBlock)(void) = ^{
[self->_delegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
};
if(_delegate)
{
callLaterBlock();
}
else //called and _delegate is not set yet, need to store to call later
{
[_pendingDelegateCalls insertObject:callLaterBlock atIndex:0];
}
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
if (self.delegate != nil)
{
[self.delegate application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
if (self.delegate != nil)
{
[self.delegate application:application didFailToRegisterForRemoteNotificationsWithError:error];
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if (self.delegate != nil)
{
[self.delegate application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
}
- (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
if(self.delegate != nil)
{
[self.delegate handlePushKitRegistered:@{@"pushKitToken": [RNNotifications deviceTokenToString:credentials.token]}];
}
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
if (self.delegate != nil)
{
[self.delegate application:nil didReceiveRemoteNotification:payload.dictionaryPayload fetchCompletionHandler:nil];
}
}
@end
......@@ -2,18 +2,10 @@
#import <React/RCTBridgeModule.h>
#import <PushKit/PushKit.h>
#import "RNNRouter.h"
#import <React/RCTEventEmitter.h>
@interface RNNotifications : NSObject <RCTBridgeModule>
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken;
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
+ (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type;
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification;
+ (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler;
+ (void)handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler;
@interface RNNotifications : RCTEventEmitter <RCTBridgeModule, RNNRerouterDelegate>
+ (NSString *)deviceTokenToString:(NSData *)deviceToken;
@end
This diff is collapsed.
......@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
432801F221F09C0F00A81AC2 /* RNNRouter.m in Sources */ = {isa = PBXBuildFile; fileRef = 432801F021F09C0F00A81AC2 /* RNNRouter.m */; };
D85B37451CC05A0900DE9EB6 /* RNNotificationsBridgeQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = D85B37441CC05A0900DE9EB6 /* RNNotificationsBridgeQueue.m */; };
D8A2F7551CB57F1A002CC8F5 /* RNNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = D8A2F7541CB57F1A002CC8F5 /* RNNotifications.m */; };
/* End PBXBuildFile section */
......@@ -25,6 +26,8 @@
/* Begin PBXFileReference section */
134814201AA4EA6300B7C361 /* libRNNotifications.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNNotifications.a; sourceTree = BUILT_PRODUCTS_DIR; };
432801F021F09C0F00A81AC2 /* RNNRouter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNRouter.m; sourceTree = "<group>"; };
432801F121F09C0F00A81AC2 /* RNNRouter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNRouter.h; sourceTree = "<group>"; };
D85B37441CC05A0900DE9EB6 /* RNNotificationsBridgeQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNotificationsBridgeQueue.m; sourceTree = "<group>"; };
D85B37461CC05A1200DE9EB6 /* RNNotificationsBridgeQueue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNotificationsBridgeQueue.h; sourceTree = "<group>"; };
D8A2F7541CB57F1A002CC8F5 /* RNNotifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNotifications.m; sourceTree = "<group>"; };
......@@ -57,6 +60,8 @@
D85B37441CC05A0900DE9EB6 /* RNNotificationsBridgeQueue.m */,
D8A2F7561CB57F28002CC8F5 /* RNNotifications.h */,
D8A2F7541CB57F1A002CC8F5 /* RNNotifications.m */,
432801F121F09C0F00A81AC2 /* RNNRouter.h */,
432801F021F09C0F00A81AC2 /* RNNRouter.m */,
134814211AA4EA7D00B7C361 /* Products */,
);
sourceTree = "<group>";
......@@ -119,6 +124,7 @@
files = (
D8A2F7551CB57F1A002CC8F5 /* RNNotifications.m in Sources */,
D85B37451CC05A0900DE9EB6 /* RNNotificationsBridgeQueue.m in Sources */,
432801F221F09C0F00A81AC2 /* RNNRouter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
......@@ -17,36 +17,48 @@ First, [Manually link](https://facebook.github.io/react-native/docs/linking-libr
Then, to enable notifications support add the following line at the top of your `AppDelegate.m`
```objective-c
#import "RNNotifications.h"
#import "RNNRouter.h"
```
And the following methods to support registration and receiving notifications:
```objective-c
// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
/ PushKit API Example
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
[RNNotifications didRegisterUserNotificationSettings:notificationSettings];
[[RNNRouter sharedInstance] didUpdatePushCredentials:credentials forType:type];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
[RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[[RNNRouter sharedInstance] application:nil didReceiveRemoteNotification:payload.dictionaryPayload fetchCompletionHandler:nil];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[RNNotifications didFailToRegisterForRemoteNotificationsWithError:error];
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[[RNNRouter sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[[RNNRouter sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
[RNNotifications didReceiveRemoteNotification:notification];
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
[[RNNRouter sharedInstance] application:application didReceiveRemoteNotification:notification fetchCompletionHandler:nil];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[[RNNRouter sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
[RNNotifications didReceiveLocalNotification:notification];
[[RNNRouter sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
```
......
......@@ -10,8 +10,9 @@
#import <UIKit/UIKit.h>
#import <PushKit/PushKit.h>
@import UserNotifications;
@interface AppDelegate : UIResponder <UIApplicationDelegate, PKPushRegistryDelegate>
@interface AppDelegate : UIResponder <UIApplicationDelegate, PKPushRegistryDelegate, UNUserNotificationCenterDelegate>
@property (nonatomic, strong) UIWindow *window;
......
......@@ -12,7 +12,7 @@
#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"
#import "RNNotifications.h"
#import "RNNRouter.h"
#import <PushKit/PushKit.h>
@implementation AppDelegate
......@@ -20,68 +20,60 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"NotificationsExampleApp"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
return YES;
}
// PushKit API Example
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
[RNNotifications didUpdatePushCredentials:credentials forType:type];
[[RNNRouter sharedInstance] didUpdatePushCredentials:credentials forType:type];
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
[RNNotifications didReceiveRemoteNotification:payload.dictionaryPayload];
[[RNNRouter sharedInstance] application:nil didReceiveRemoteNotification:payload.dictionaryPayload fetchCompletionHandler:nil];
}
// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNNotifications didRegisterUserNotificationSettings:notificationSettings];
[[RNNRouter sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[[RNNRouter sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
[RNNotifications didReceiveRemoteNotification:notification];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
[RNNotifications didReceiveLocalNotification:notification];
[[RNNRouter sharedInstance] application:application didReceiveRemoteNotification:notification fetchCompletionHandler:nil];
}
// Required for the notification actions.
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RNNotifications handleActionWithIdentifier:identifier forLocalNotification:notification withResponseInfo:responseInfo completionHandler:completionHandler];
[[RNNRouter sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
[RNNotifications handleActionWithIdentifier:identifier forRemoteNotification:userInfo withResponseInfo:responseInfo completionHandler:completionHandler];
[[RNNRouter sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
@end
......@@ -8,6 +8,6 @@
"dependencies": {
"react": "16.6.0-alpha.8af6728",
"react-native": "^0.57.4",
"react-native-notifications": "latest"
"react-native-notifications": "git://github.com/wix/react-native-notifications.git#iosDeprecationsFixes"
}
}
......@@ -2,10 +2,11 @@
* @flow
*/
"use strict";
import { NativeModules, DeviceEventEmitter, NativeAppEventEmitter } from "react-native";
import { NativeModules, NativeEventEmitter } from "react-native";
import Map from "core-js/library/es6/map";
import uuid from "uuid";
const NativeRNNotifications = NativeModules.RNNotifications; // eslint-disable-line no-unused-vars
const {RNNotifications} = NativeModules; // eslint-disable-line no-unused-vars
const rnnotificationsEmitter = new NativeEventEmitter(RNNotifications);
import IOSNotification from "./notification.ios";
export const DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT = "remoteNotificationsRegistered";
......@@ -64,22 +65,22 @@ export default class NotificationsIOS {
let listener;
if (type === DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT) {
listener = DeviceEventEmitter.addListener(
listener = rnnotificationsEmitter.addListener(
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT,
registration => handler(registration.deviceToken)
);
} else if (type === DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT) {
listener = DeviceEventEmitter.addListener(
listener = rnnotificationsEmitter.addListener(
DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT,
error => handler(error)
);
} else if (type === DEVICE_PUSH_KIT_REGISTERED_EVENT) {
listener = DeviceEventEmitter.addListener(
listener = rnnotificationsEmitter.addListener(
DEVICE_PUSH_KIT_REGISTERED_EVENT,
registration => handler(registration.pushKitToken)
);
} else {
listener = DeviceEventEmitter.addListener(
listener = rnnotificationsEmitter.addListener(
type,
notification => handler(new IOSNotification(notification))
);
......@@ -111,7 +112,7 @@ export default class NotificationsIOS {
action.notification = new IOSNotification(action.notification);
actionHandler(action, () => {
NativeRNNotifications.completionHandler(action.completionKey);
RNNotifications.completionHandler(action.completionKey);
});
}
}
......@@ -124,7 +125,7 @@ export default class NotificationsIOS {
if (categories) {
// subscribe once for all actions
_actionListener = NativeAppEventEmitter.addListener(DEVICE_NOTIFICATION_ACTION_RECEIVED, this._actionHandlerDispatcher.bind(this));
_actionListener = rnnotificationsEmitter.addListener(DEVICE_NOTIFICATION_ACTION_RECEIVED, this._actionHandlerDispatcher.bind(this));
notificationCategories = categories.map(category => {
return Object.assign({}, category.options, {
......@@ -138,14 +139,14 @@ export default class NotificationsIOS {
});
}
NativeRNNotifications.requestPermissionsWithCategories(notificationCategories);
RNNotifications.requestPermissionsWithCategories(notificationCategories);
}
/**
* Unregister for all remote notifications received via Apple Push Notification service.
*/
static abandonPermissions() {
NativeRNNotifications.abandonPermissions();
RNNotifications.abandonPermissions();
}
/**
......@@ -161,31 +162,31 @@ export default class NotificationsIOS {
}
static getBadgesCount(callback: Function) {
NativeRNNotifications.getBadgesCount(callback);
RNNotifications.getBadgesCount(callback);
}
static setBadgesCount(count: number) {
NativeRNNotifications.setBadgesCount(count);
RNNotifications.setBadgesCount(count);
}
static registerPushKit() {
NativeRNNotifications.registerPushKit();
RNNotifications.registerPushKit();
}
static backgroundTimeRemaining(callback: Function) {
NativeRNNotifications.backgroundTimeRemaining(callback);
RNNotifications.backgroundTimeRemaining(callback);
}
static consumeBackgroundQueue() {
NativeRNNotifications.consumeBackgroundQueue();
RNNotifications.consumeBackgroundQueue();
}
static log(message: string) {
NativeRNNotifications.log(message);
RNNotifications.log(message);
}
static async getInitialNotification() {
const notification = await NativeRNNotifications.getInitialNotification();
const notification = await RNNotifications.getInitialNotification();
if (notification) {
return new IOSNotification(notification);
} else {
......@@ -209,32 +210,32 @@ export default class NotificationsIOS {
*/
static localNotification(notification: Object) {
const notificationId = uuid.v4();
NativeRNNotifications.localNotification(notification, notificationId);
RNNotifications.localNotification(notification, notificationId);
return notificationId;
}
static cancelLocalNotification(notificationId: String) {
NativeRNNotifications.cancelLocalNotification(notificationId);
RNNotifications.cancelLocalNotification(notificationId);
}
static cancelAllLocalNotifications() {
NativeRNNotifications.cancelAllLocalNotifications();
RNNotifications.cancelAllLocalNotifications();
}
static isRegisteredForRemoteNotifications() {
return NativeRNNotifications.isRegisteredForRemoteNotifications();
return RNNotifications.isRegisteredForRemoteNotifications();
}
static checkPermissions() {
return NativeRNNotifications.checkPermissions();
return RNNotifications.checkPermissions();
}
/**
* Remove all delivered notifications from Notification Center
*/
static removeAllDeliveredNotifications() {
return NativeRNNotifications.removeAllDeliveredNotifications();
return RNNotifications.removeAllDeliveredNotifications();
}
/**
......@@ -243,7 +244,7 @@ export default class NotificationsIOS {
* @param identifiers Array of notification identifiers
*/
static removeDeliveredNotifications(identifiers: Array<String>) {
return NativeRNNotifications.removeDeliveredNotifications(identifiers);
return RNNotifications.removeDeliveredNotifications(identifiers);
}
/**
......@@ -262,6 +263,6 @@ export default class NotificationsIOS {
* - `fireDate` : The date and time when the system should deliver the notification. if not specified, the notification will be dispatched immediately.
*/
static getDeliveredNotifications(callback: (notifications: Array<Object>) => void) {
return NativeRNNotifications.getDeliveredNotifications(callback);
return RNNotifications.getDeliveredNotifications(callback);
}
}
{
"name": "react-native-notifications",
"version": "1.2.6",
"version": "1.3.0",
"description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android",
"author": "Lidan Hifi <lidan.hifi@gmail.com>",
"license": "MIT",
......
......@@ -18,8 +18,6 @@ describe("NotificationsIOS", () => {
/*eslint-disable indent*/
let deviceAddEventListener,
deviceRemoveEventListener,
nativeAppAddEventListener,
nativeAppRemoveEventListener,
nativeRequestPermissionsWithCategories,
nativeAbandonPermissions,
nativeRegisterPushKit,
......@@ -37,7 +35,8 @@ describe("NotificationsIOS", () => {
nativeGetDeliveredNotifications;
let NotificationsIOS, NotificationAction, NotificationCategory;
let someHandler = () => {};
let someHandler = () => {
};
let constantGuid = "some-random-uuid";
let identifiers = ["some-random-uuid", "other-random-uuid"];
/*eslint-enable indent*/
......@@ -45,8 +44,6 @@ describe("NotificationsIOS", () => {
before(() => {
deviceAddEventListener = sinon.spy();
deviceRemoveEventListener = sinon.spy();
nativeAppAddEventListener = sinon.spy();
nativeAppRemoveEventListener = sinon.spy();
nativeRequestPermissionsWithCategories = sinon.spy();
nativeAbandonPermissions = sinon.spy();
nativeRegisterPushKit = sinon.spy();
......@@ -63,6 +60,7 @@ describe("NotificationsIOS", () => {
nativeRemoveDeliveredNotifications = sinon.spy();
nativeGetDeliveredNotifications = sinon.spy();
let libUnderTest = proxyquire("../index.ios", {
"uuid": {
v4: () => constantGuid
......@@ -87,20 +85,12 @@ describe("NotificationsIOS", () => {
getDeliveredNotifications: nativeGetDeliveredNotifications
}
},
NativeAppEventEmitter: {
addListener: (...args) => {
nativeAppAddEventListener(...args);
return { remove: nativeAppRemoveEventListener };
}
},
DeviceEventEmitter: {
NativeEventEmitter: () => ({
addListener: (...args) => {
deviceAddEventListener(...args);
return { remove: deviceRemoveEventListener };
return {remove: deviceRemoveEventListener};
}
},
}),
"@noCallThru": true
}
});
......@@ -113,8 +103,6 @@ describe("NotificationsIOS", () => {
afterEach(() => {
deviceAddEventListener.reset();
deviceRemoveEventListener.reset();
nativeAppAddEventListener.reset();
nativeAppRemoveEventListener.reset();
nativeRequestPermissionsWithCategories.reset();
nativeAbandonPermissions.reset();
nativeRegisterPushKit.reset();
......@@ -133,8 +121,6 @@ describe("NotificationsIOS", () => {
after(() => {
deviceAddEventListener = null;
deviceRemoveEventListener = null;
nativeAppAddEventListener = null;
nativeAppRemoveEventListener = null;
nativeRequestPermissionsWithCategories = null;
nativeAbandonPermissions = null;
nativeRegisterPushKit = null;
......@@ -200,7 +186,8 @@ describe("NotificationsIOS", () => {
};
beforeEach(() => {
someAction = new NotificationAction(actionOpts, () => {});
someAction = new NotificationAction(actionOpts, () => {
});
someCategory = new NotificationCategory({
identifier: "SOME_CATEGORY",
......@@ -226,11 +213,11 @@ describe("NotificationsIOS", () => {
expect(nativeRequestPermissionsWithCategories).to.have.been.calledWith([]);
});
it("should subscribe to 'notificationActionReceived' event once, with a single event handler", () => {
("should subscribe to 'notificationActionReceived' event once, with a single event handler", () => {
NotificationsIOS.requestPermissions([someCategory]);
expect(nativeAppAddEventListener).to.have.been.calledOnce;
expect(nativeAppAddEventListener).to.have.been.calledWith("notificationActionReceived", sinon.match.func);
expect(deviceAddEventListener).to.have.been.calledOnce;
// expect(nativeAppAddEventListener).to.have.been.calledWith("notificationActionReceived", sinon.match.func);
});
});
......@@ -238,7 +225,7 @@ describe("NotificationsIOS", () => {
it("should remove 'notificationActionReceived' event handler", () => {
NotificationsIOS.resetCategories();
expect(nativeAppRemoveEventListener).to.have.been.calledOnce;
expect(deviceRemoveEventListener).to.have.been.calledOnce;
});
});
......@@ -279,7 +266,8 @@ describe("NotificationsIOS", () => {
describe("Get background remaining time", () => {
it("should call native background remaining time method", () => {
let someCallback = (time) => { };
let someCallback = (time) => {
};
NotificationsIOS.backgroundTimeRemaining(someCallback);
......
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