Page MenuHomePhabricator

D6070.id20220.diff
No OneTemporary

D6070.id20220.diff

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
@@ -340,4 +340,104 @@
return [result copy];
}
++ (void)requestPermissions {
+ UNUserNotificationCenter *center =
+ [UNUserNotificationCenter currentNotificationCenter];
+ UNAuthorizationOptions options = UNAuthorizationOptionAlert +
+ UNAuthorizationOptionSound + UNAuthorizationOptionBadge;
+ [center
+ requestAuthorizationWithOptions:options
+ completionHandler:^(
+ BOOL granted, NSError *_Nullable error) {
+ if (!granted) {
+ NSDictionary *errorInfo;
+ if (error) {
+ errorInfo = @{
+ @"code" : [NSNumber numberWithInteger:error.code],
+ @"domain" : error.domain,
+ @"localizedDescription" : error.localizedDescription
+ };
+ } else {
+ errorInfo = @{};
+ }
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:
+ CommIOSNotificationsRegistrationFailed
+ object:self
+ userInfo:errorInfo];
+ return;
+ }
+ if ([UIApplication instancesRespondToSelector:@selector
+ (registerForRemoteNotifications)]) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[UIApplication sharedApplication]
+ registerForRemoteNotifications];
+ });
+ }
+ }];
+}
+
+/*
+ React Native exported methods
+*/
+RCT_EXPORT_METHOD(requestPermissions) {
+ [CommIOSNotifications requestPermissions];
+}
+
+RCT_EXPORT_METHOD(consumeBackgroundQueue) {
+ // Mark JS Thread as ready
+ [CommIOSNotificationsBridgeQueue sharedInstance].jsIsReady = YES;
+
+ // Push actions to JS
+ [[CommIOSNotificationsBridgeQueue sharedInstance]
+ consumeActionsQueue:^(NSDictionary *action) {
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:CommIOSNotificationsActionTriggered
+ object:self
+ userInfo:action];
+ }];
+
+ // Push background notifications to JS
+ [[CommIOSNotificationsBridgeQueue sharedInstance]
+ consumeNotificationsQueue:^(NSDictionary *notifInfo) {
+ NSDictionary *notification = notifInfo[@"notification"];
+ RCTRemoteNotificationCallback completionHandler =
+ notifInfo[@"completionHandler"];
+ [CommIOSNotifications didReceiveRemoteNotification:notification
+ fetchCompletionHandler:completionHandler];
+ }];
+
+ // Push opened local notifications
+ NSDictionary *openedLocalNotification =
+ [CommIOSNotificationsBridgeQueue sharedInstance].openedLocalNotification;
+ if (openedLocalNotification) {
+ [CommIOSNotificationsBridgeQueue sharedInstance].openedLocalNotification =
+ nil;
+ NSDictionary *notifInfo = @{@"notification" : openedLocalNotification};
+ [CommIOSNotifications didNotificationOpen:notifInfo];
+ }
+
+ // Push opened remote notifications
+ NSDictionary *openedRemoteNotification =
+ [CommIOSNotificationsBridgeQueue sharedInstance].openedRemoteNotification;
+ if (openedRemoteNotification) {
+ [CommIOSNotificationsBridgeQueue sharedInstance].openedRemoteNotification =
+ nil;
+ NSDictionary *notifInfo = @{@"notification" : openedRemoteNotification};
+ [CommIOSNotifications didNotificationOpen:notifInfo];
+ }
+}
+
+RCT_EXPORT_METHOD(checkPermissions
+ : (RCTPromiseResolveBlock)resolve reject
+ : (RCTPromiseRejectBlock)reject) {
+ UIUserNotificationSettings *currentSettings =
+ [[UIApplication sharedApplication] currentUserNotificationSettings];
+ resolve(@{
+ @"badge" : @((currentSettings.types & UIUserNotificationTypeBadge) > 0),
+ @"sound" : @((currentSettings.types & UIUserNotificationTypeSound) > 0),
+ @"alert" : @((currentSettings.types & UIUserNotificationTypeAlert) > 0),
+ });
+}
+
@end

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 12:17 PM (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2497771
Default Alt Text
D6070.id20220.diff (4 KB)

Event Timeline