Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3294213
D8106.id27638.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D8106.id27638.diff
View Options
diff --git a/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm b/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm
--- a/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm
+++ b/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm
@@ -21,6 +21,19 @@
NSString *const CommIOSNotificationsReceivedBackground =
@"CommIOSNotificationsReceivedBackground";
+/*
+ JavaScript Events Names
+*/
+NSString *const remoteNotificationsRegistered =
+ @"remoteNotificationsRegistered";
+NSString *const remoteNotificationsRegistrationFailed =
+ @"remoteNotificationsRegistrationFailed";
+NSString *const notificationReceivedForeground =
+ @"notificationReceivedForeground";
+NSString *const notificationOpened = @"notificationOpened";
+NSString *const notificationReceivedBackground =
+ @"notificationReceivedBackground";
+
/*
UIBackgroundFetchResult enum converter to pass fetch result value
between Objective - C and JavaScript
@@ -104,11 +117,11 @@
- (NSArray<NSString *> *)supportedEvents {
return @[
- @"remoteNotificationsRegistered",
- @"remoteNotificationsRegistrationFailed",
- @"notificationReceivedForeground",
- @"notificationOpened",
- @"notificationReceivedBackground",
+ remoteNotificationsRegistered,
+ remoteNotificationsRegistrationFailed,
+ notificationReceivedForeground,
+ notificationOpened,
+ notificationReceivedBackground,
];
}
@@ -119,7 +132,13 @@
return @{
@"FETCH_RESULT_NEW_DATA" : @"UIBackgroundFetchResultNewData",
@"FETCH_RESULT_NO_DATA" : @"UIBackgroundFetchResultNoData",
- @"FETCH_RESULT_FAILED" : @"UIBackgroundFetchResultFailed"
+ @"FETCH_RESULT_FAILED" : @"UIBackgroundFetchResultFailed",
+ @"REMOTE_NOTIFICATIONS_REGISTERED_EVENT" : remoteNotificationsRegistered,
+ @"REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT" :
+ remoteNotificationsRegistrationFailed,
+ @"NOTIFICATION_RECEIVED_FOREGROUND_EVENT" : notificationReceivedForeground,
+ @"NOTIFICATION_OPENED_EVENT" : notificationOpened,
+ @"NOTIFICATION_RECEIVED_BACKGROUND_EVENT" : notificationReceivedBackground
};
}
@@ -211,13 +230,13 @@
}
/*
- JavaScript Events
+ JavaScript Events Emitters
*/
- (void)handleNotificationsRegistered:(NSNotification *)notification {
if (!_hasListeners) {
return;
}
- [self sendEventWithName:@"remoteNotificationsRegistered"
+ [self sendEventWithName:remoteNotificationsRegistered
body:notification.userInfo];
}
@@ -225,7 +244,7 @@
if (!_hasListeners) {
return;
}
- [self sendEventWithName:@"remoteNotificationsRegistrationFailed"
+ [self sendEventWithName:remoteNotificationsRegistrationFailed
body:notification.userInfo];
}
@@ -254,21 +273,21 @@
return;
}
[self handleNotifInfo:sysNotif.userInfo
- withName:@"notificationReceivedForeground"];
+ withName:notificationReceivedForeground];
}
- (void)handleNotificationOpened:(NSNotification *)sysNotif {
if (!_hasListeners) {
return;
}
- [self handleNotifInfo:sysNotif.userInfo withName:@"notificationOpened"];
+ [self handleNotifInfo:sysNotif.userInfo withName:notificationOpened];
}
- (void)handleNotificationReceivedBackground:(NSNotification *)sysNotif {
if (!_hasListeners) {
return;
}
- [self sendEventWithName:@"notificationReceivedBackground"
+ [self sendEventWithName:notificationReceivedBackground
body:sysNotif.userInfo];
}
diff --git a/native/push/ios.js b/native/push/ios.js
--- a/native/push/ios.js
+++ b/native/push/ios.js
@@ -9,6 +9,17 @@
type PushPermissions = { alert?: boolean, badge?: boolean, sound?: boolean };
+type CommIOSNotificationsConstants = {
+ +FETCH_RESULT_NO_DATA: 'UIBackgroundFetchResultNoData',
+ +FETCH_RESULT_NEW_DATA: 'UIBackgroundFetchResultNewData',
+ +FETCH_RESULT_FAILED: 'UIBackgroundFetchResultFailed',
+ +REMOTE_NOTIFICATIONS_REGISTERED_EVENT: 'remoteNotificationsRegistered',
+ +REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT: 'remoteNotificationsRegistrationFailed',
+ +NOTIFICATION_RECEIVED_FOREGROUND_EVENT: 'notificationReceivedForeground',
+ +NOTIFICATION_OPENED_EVENT: 'notificationOpened',
+ +NOTIFICATION_RECEIVED_BACKGROUND_EVENT: 'notificationReceivedBackground',
+};
+
type CommIOSNotificationsModuleType = {
+requestPermissions: () => void,
+checkPermissions: () => PushPermissions,
@@ -22,13 +33,11 @@
) => void,
) => void,
+completeNotif: (id: string, fetchResult: string) => void,
- +getConstants: () => { [string]: string },
+ +getConstants: () => CommIOSNotificationsConstants,
// required since CommIOSNotifications subclasses RCTEventEmitter
+addListener: (eventName: string) => void,
+removeListeners: (count: number) => void,
- +FETCH_RESULT_NO_DATA: string,
- +FETCH_RESULT_NO_DATA: string,
- +FETCH_RESULT_FAILED: string,
+ ...CommIOSNotificationsConstants,
};
const CommIOSNotifications: CommIOSNotificationsModuleType =
diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js
--- a/native/push/push-handler.react.js
+++ b/native/push/push-handler.react.js
@@ -131,24 +131,28 @@
getCommIOSNotificationsEventEmitter();
this.iosNotificationEventSubscriptions.push(
commIOSNotificationsEventEmitter.addListener(
- 'remoteNotificationsRegistered',
+ CommIOSNotifications.getConstants()
+ .REMOTE_NOTIFICATIONS_REGISTERED_EVENT,
registration =>
this.registerPushPermissions(registration?.deviceToken),
),
commIOSNotificationsEventEmitter.addListener(
- 'remoteNotificationsRegistrationFailed',
+ CommIOSNotifications.getConstants()
+ .REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT,
this.failedToRegisterPushPermissionsIOS,
),
commIOSNotificationsEventEmitter.addListener(
- 'notificationReceivedForeground',
+ CommIOSNotifications.getConstants()
+ .NOTIFICATION_RECEIVED_FOREGROUND_EVENT,
this.iosForegroundNotificationReceived,
),
commIOSNotificationsEventEmitter.addListener(
- 'notificationOpened',
+ CommIOSNotifications.getConstants().NOTIFICATION_OPENED_EVENT,
this.iosNotificationOpened,
),
commIOSNotificationsEventEmitter.addListener(
- 'notificationReceivedBackground',
+ CommIOSNotifications.getConstants()
+ .NOTIFICATION_RECEIVED_BACKGROUND_EVENT,
backgroundData => this.saveMessageInfos(backgroundData?.messageInfos),
),
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 6:48 PM (20 h, 35 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2529882
Default Alt Text
D8106.id27638.diff (6 KB)
Attached To
Mode
D8106: Refactor CommIOSNotifications native and JavaScript code so that JavaScript registers to events using getConstants object instead of hardcoded strings
Attached
Detach File
Event Timeline
Log In to Comment