Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3249140
D6070.id21419.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
D6070.id21419.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
@@ -265,4 +265,83 @@
return jsReadableNotification;
}
+/*
+ React Native exported methods
+*/
+RCT_EXPORT_METHOD(requestPermissions) {
+ UNAuthorizationOptions options = UNAuthorizationOptionAlert +
+ UNAuthorizationOptionSound + UNAuthorizationOptionBadge;
+ void (^authorizationRequestCompletionHandler)(BOOL, NSError *) =
+ ^(BOOL granted, NSError *_Nullable error) {
+ if (granted &&
+ [UIApplication instancesRespondToSelector:@selector
+ (registerForRemoteNotifications)]) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
+ });
+ return;
+ }
+
+ NSDictionary *errorInfo = @{};
+ if (error) {
+ errorInfo = @{
+ @"code" : [NSNumber numberWithInteger:error.code],
+ @"domain" : error.domain,
+ @"localizedDescription" : error.localizedDescription
+ };
+ }
+
+ [NSNotificationCenter.defaultCenter
+ postNotificationName:CommIOSNotificationsRegistrationFailed
+ object:self
+ userInfo:errorInfo];
+ };
+ [UNUserNotificationCenter.currentNotificationCenter
+ requestAuthorizationWithOptions:options
+ completionHandler:authorizationRequestCompletionHandler];
+}
+
+RCT_EXPORT_METHOD(consumeBackgroundQueue) {
+ CommIOSNotificationsBridgeQueue.sharedInstance.jsReady = YES;
+
+ // 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 = [_bridge.launchOptions
+ objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
+ 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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 12:27 PM (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2497833
Default Alt Text
D6070.id21419.diff (3 KB)
Attached To
Mode
D6070: Export minimal set of CommIOSNotifications RCT methods to use it in AppDelegate
Attached
Detach File
Event Timeline
Log In to Comment