Page MenuHomePhabricator

D6070.id20731.diff
No OneTemporary

D6070.id20731.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
@@ -268,4 +268,93 @@
return [result copy];
}
+/*
+ React Native exported methods
+*/
+RCT_EXPORT_METHOD(requestPermissions) {
+ UNUserNotificationCenter *center =
+ [UNUserNotificationCenter currentNotificationCenter];
+ UNAuthorizationOptions options = UNAuthorizationOptionAlert +
+ UNAuthorizationOptionSound + UNAuthorizationOptionBadge;
+ [center
+ requestAuthorizationWithOptions:options
+ completionHandler:^(
+ BOOL granted, NSError *_Nullable error) {
+ if (granted &&
+ [UIApplication instancesRespondToSelector:@selector
+ (registerForRemoteNotifications)]) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[UIApplication sharedApplication]
+ registerForRemoteNotifications];
+ });
+ return;
+ }
+
+ NSDictionary *errorInfo = error ? @{
+ @"code" : [NSNumber numberWithInteger:error.code],
+ @"domain" : error.domain,
+ @"localizedDescription" : error.localizedDescription
+ }
+ : @{};
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:
+ CommIOSNotificationsRegistrationFailed
+ object:self
+ userInfo:errorInfo];
+ }];
+}
+
+RCT_EXPORT_METHOD(consumeBackgroundQueue) {
+ // Mark JS Thread as ready
+ [CommIOSNotificationsBridgeQueue sharedInstance].jsReady = YES;
+
+ // Push actions to JS
+ [[CommIOSNotificationsBridgeQueue sharedInstance]
+ processActions:^(NSDictionary *action) {
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:CommIOSNotificationsActionTriggered
+ object:self
+ userInfo:action];
+ }];
+
+ // Push background notifications to JS
+ [[CommIOSNotificationsBridgeQueue sharedInstance]
+ processNotifications:^(NSDictionary *notifInfo) {
+ NSDictionary *notification = notifInfo[@"notification"];
+ RCTRemoteNotificationCallback completionHandler =
+ notifInfo[@"completionHandler"];
+ [CommIOSNotifications didReceiveRemoteNotification:notification
+ fetchCompletionHandler:completionHandler];
+ }];
+
+ // Push opened remote notifications
+ NSDictionary *openedRemoteNotification =
+ [CommIOSNotificationsBridgeQueue sharedInstance].openedRemoteNotification;
+ if (openedRemoteNotification) {
+ [CommIOSNotificationsBridgeQueue sharedInstance].openedRemoteNotification =
+ nil;
+ NSDictionary *notifInfo = @{@"notification" : openedRemoteNotification};
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:CommIOSNotificationsOpened
+ object:self
+ userInfo:notifInfo];
+ }
+}
+
+RCT_EXPORT_METHOD(checkPermissions
+ : (RCTPromiseResolveBlock)resolve reject
+ : (RCTPromiseRejectBlock)reject) {
+ __block NSDictionary *permissions;
+ [UNUserNotificationCenter.currentNotificationCenter
+ getNotificationSettingsWithCompletionHandler:^(
+ UNNotificationSettings *_Nonnull settings) {
+ permissions = @{
+ @"badge" : @(settings.badgeSetting == UNNotificationSettingEnabled),
+ @"sound" : @(settings.soundSetting == UNNotificationSettingEnabled),
+ @"alert" : @(settings.alertSetting == UNNotificationSettingEnabled)
+ };
+ resolve(permissions);
+ }];
+}
+
@end

File Metadata

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

Event Timeline