Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3249236
D6067.id21429.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D6067.id21429.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
@@ -85,6 +85,82 @@
];
}
+/*
+ Public methods
+*/
++ (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
+ NSString *token = [deviceToken isKindOfClass:[NSString class]]
+ ? deviceToken
+ : [self deviceTokenToString:deviceToken];
+ [NSNotificationCenter.defaultCenter
+ postNotificationName:CommIOSNotificationsRegistered
+ object:self
+ userInfo:@{@"deviceToken" : token}];
+}
+
++ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
+ [NSNotificationCenter.defaultCenter
+ postNotificationName:CommIOSNotificationsRegistrationFailed
+ object:self
+ userInfo:@{
+ @"code" : [NSNumber numberWithInteger:error.code],
+ @"domain" : error.domain,
+ @"localizedDescription" : error.localizedDescription
+ }];
+}
+
++ (void)didReceiveRemoteNotification:(NSDictionary *)notification
+ fetchCompletionHandler:
+ (void (^)(UIBackgroundFetchResult))completionHandler {
+
+ NSDictionary *notifInfo = @{
+ @"notification" : notification,
+ @"completionHandler" : completionHandler
+ };
+ UIApplicationState state = [UIApplication sharedApplication].applicationState;
+
+ if (!CommIOSNotificationsBridgeQueue.sharedInstance.jsReady) {
+ [CommIOSNotificationsBridgeQueue.sharedInstance putNotification:notifInfo];
+ return;
+ }
+
+ if (state == UIApplicationStateActive) {
+ [NSNotificationCenter.defaultCenter
+ postNotificationName:CommIOSNotificationsReceivedForeground
+ object:self
+ userInfo:notifInfo];
+ } else if (state == UIApplicationStateInactive) {
+ [NSNotificationCenter.defaultCenter
+ postNotificationName:CommIOSNotificationsOpened
+ object:self
+ userInfo:notifInfo];
+ }
+}
+
++ (void)clearNotificationFromNotificationsCenter:(NSString *)notificationId
+ completionHandler:
+ (void (^)(UIBackgroundFetchResult))
+ completionHandler {
+ [UNUserNotificationCenter.currentNotificationCenter
+ getDeliveredNotificationsWithCompletionHandler:^(
+ NSArray<UNNotification *> *_Nonnull notifications) {
+ for (UNNotification *notif in notifications) {
+ if ([notificationId isEqual:notif.request.content.userInfo[@"id"]]) {
+ NSArray *identifiers =
+ [NSArray arrayWithObjects:notif.request.identifier, nil];
+ [UNUserNotificationCenter.currentNotificationCenter
+ removeDeliveredNotificationsWithIdentifiers:identifiers];
+ }
+ }
+ if (completionHandler) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ completionHandler(UIBackgroundFetchResultNewData);
+ });
+ }
+ }];
+ return;
+}
+
/*
JavaScript Events
*/
@@ -142,6 +218,15 @@
/*
Helper methods
*/
++ (NSString *)deviceTokenToString:(NSData *)deviceToken {
+ NSMutableString *result = [NSMutableString string];
+ const unsigned char *bytes = (const unsigned char *)deviceToken.bytes;
+ for (NSUInteger i = 0; i < deviceToken.length; i++) {
+ [result appendFormat:@"%02x", bytes[i]];
+ }
+ return [result copy];
+}
+
+ (NSDictionary *)parseNotificationToJSReadableObject:
(NSDictionary *)notification
withRequestIdentifier:(NSString *)identifier {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 12:52 PM (21 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2497514
Default Alt Text
D6067.id21429.diff (3 KB)
Attached To
Mode
D6067: Implement native public notifications API
Attached
Detach File
Event Timeline
Log In to Comment