expose remote/local flag from native side instead of JS side
Reviewed By: hedgerwang Differential Revision: D3536661 fbshipit-source-id: ae613daabe2ae581ebeabd8649b529d5fe6c5493
This commit is contained in:
parent
33a1f28654
commit
58202b7ba4
|
@ -19,10 +19,6 @@ const PushNotificationEmitter = new NativeEventEmitter(RCTPushNotificationManage
|
|||
|
||||
const _notifHandlers = new Map();
|
||||
|
||||
//TODO: remove this once all call sites for popInitialNotification() have been removed
|
||||
let _initialNotification = RCTPushNotificationManager &&
|
||||
RCTPushNotificationManager.initialNotification;
|
||||
|
||||
const DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
|
||||
const NOTIF_REGISTER_EVENT = 'remoteNotificationsRegistered';
|
||||
const DEVICE_LOCAL_NOTIF_EVENT = 'localNotificationReceived';
|
||||
|
@ -92,7 +88,7 @@ class PushNotificationIOS {
|
|||
* - `soundName` : The sound played when the notification is fired (optional).
|
||||
* - `category` : The category of this notification, required for actionable notifications (optional).
|
||||
* - `userInfo` : An optional object containing additional notification data.
|
||||
* - `applicationIconBadgeNumber` (optional) : The number to display as the app’s icon badge. The default value of this property is 0, which means that no badge is displayed.
|
||||
* - `applicationIconBadgeNumber` (optional) : The number to display as the app's icon badge. The default value of this property is 0, which means that no badge is displayed.
|
||||
*/
|
||||
static presentLocalNotification(details: Object) {
|
||||
RCTPushNotificationManager.presentLocalNotification(details);
|
||||
|
@ -109,7 +105,7 @@ class PushNotificationIOS {
|
|||
* - `soundName` : The sound played when the notification is fired (optional).
|
||||
* - `category` : The category of this notification, required for actionable notifications (optional).
|
||||
* - `userInfo` : An optional object containing additional notification data.
|
||||
* - `applicationIconBadgeNumber` (optional) : The number to display as the app’s icon badge. Setting the number to 0 removes the icon badge.
|
||||
* - `applicationIconBadgeNumber` (optional) : The number to display as the app's icon badge. Setting the number to 0 removes the icon badge.
|
||||
*/
|
||||
static scheduleLocalNotification(details: Object) {
|
||||
RCTPushNotificationManager.scheduleLocalNotification(details);
|
||||
|
@ -177,7 +173,6 @@ class PushNotificationIOS {
|
|||
listener = PushNotificationEmitter.addListener(
|
||||
DEVICE_NOTIF_EVENT,
|
||||
(notifData) => {
|
||||
notifData.remote = true;
|
||||
handler(new PushNotificationIOS(notifData));
|
||||
}
|
||||
);
|
||||
|
@ -185,7 +180,6 @@ class PushNotificationIOS {
|
|||
listener = PushNotificationEmitter.addListener(
|
||||
DEVICE_LOCAL_NOTIF_EVENT,
|
||||
(notifData) => {
|
||||
notifData.remote = false;
|
||||
handler(new PushNotificationIOS(notifData));
|
||||
}
|
||||
);
|
||||
|
@ -289,21 +283,6 @@ class PushNotificationIOS {
|
|||
RCTPushNotificationManager.checkPermissions(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: An initial notification will be available if the app was
|
||||
* cold-launched from a notification.
|
||||
*
|
||||
* The first caller of `popInitialNotification` will get the initial
|
||||
* notification object, or `null`. Subsequent invocations will return null.
|
||||
*/
|
||||
static popInitialNotification() {
|
||||
console.warn('PushNotificationIOS.popInitialNotification() is deprecated. Use getInitialNotification() instead.');
|
||||
var initialNotification = _initialNotification &&
|
||||
new PushNotificationIOS(_initialNotification);
|
||||
_initialNotification = null;
|
||||
return initialNotification;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the app launch was triggered by a push notification,
|
||||
* it will give the notification object, otherwise it will give `null`
|
||||
|
|
|
@ -71,6 +71,7 @@ static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notificatio
|
|||
formattedLocalNotification[@"category"] = RCTNullIfNil(notification.category);
|
||||
formattedLocalNotification[@"soundName"] = RCTNullIfNil(notification.soundName);
|
||||
formattedLocalNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(notification.userInfo));
|
||||
formattedLocalNotification[@"remote"] = @NO;
|
||||
return formattedLocalNotification;
|
||||
}
|
||||
|
||||
|
@ -113,25 +114,6 @@ RCT_EXPORT_MODULE()
|
|||
@"remoteNotificationsRegistered"];
|
||||
}
|
||||
|
||||
// TODO: Once all JS call sites for popInitialNotification have
|
||||
// been removed we can get rid of this
|
||||
- (NSDictionary<NSString *, id> *)constantsToExport
|
||||
{
|
||||
NSDictionary<NSString *, id> *initialNotification =
|
||||
self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
|
||||
|
||||
UILocalNotification *initialLocalNotification =
|
||||
self.bridge.launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
|
||||
|
||||
if (initialNotification) {
|
||||
return @{@"initialNotification": [initialNotification copy]};
|
||||
} else if (initialLocalNotification) {
|
||||
return @{@"initialNotification": RCTFormatLocalNotification(initialLocalNotification)};
|
||||
} else {
|
||||
return @{@"initialNotification": (id)kCFNull};
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
|
||||
{
|
||||
if ([UIApplication instancesRespondToSelector:@selector(registerForRemoteNotifications)]) {
|
||||
|
@ -176,7 +158,9 @@ RCT_EXPORT_MODULE()
|
|||
|
||||
- (void)handleRemoteNotificationReceived:(NSNotification *)notification
|
||||
{
|
||||
[self sendEventWithName:@"remoteNotificationReceived" body:notification.userInfo];
|
||||
NSMutableDictionary *userInfo = [notification.userInfo mutableCopy];
|
||||
userInfo[@"remote"] = @YES;
|
||||
[self sendEventWithName:@"remoteNotificationReceived" body:userInfo];
|
||||
}
|
||||
|
||||
- (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
|
||||
|
@ -329,14 +313,15 @@ RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userI
|
|||
RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve
|
||||
reject:(__unused RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
NSDictionary<NSString *, id> *initialNotification =
|
||||
self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
|
||||
NSMutableDictionary<NSString *, id> *initialNotification =
|
||||
[self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] mutableCopy];
|
||||
|
||||
UILocalNotification *initialLocalNotification =
|
||||
self.bridge.launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
|
||||
|
||||
if (initialNotification) {
|
||||
resolve([initialNotification copy]);
|
||||
initialNotification[@"remote"] = @YES;
|
||||
resolve(initialNotification);
|
||||
} else if (initialLocalNotification) {
|
||||
resolve(RCTFormatLocalNotification(initialLocalNotification));
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue