Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3249125
D6070.id21009.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.id21009.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
@@ -257,4 +257,84 @@
return jsReadableNotification;
}
+/*
+ React Native exported methods
+*/
+RCT_EXPORT_METHOD(requestPermissions) {
+ UNAuthorizationOptions options = UNAuthorizationOptionAlert +
+ UNAuthorizationOptionSound + UNAuthorizationOptionBadge;
+ [UNUserNotificationCenter.currentNotificationCenter
+ 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 = @{};
+ if (error) {
+ errorInfo = @{
+ @"code" : [NSNumber numberWithInteger:error.code],
+ @"domain" : error.domain,
+ @"localizedDescription" : error.localizedDescription
+ };
+ }
+
+ [NSNotificationCenter.defaultCenter
+ postNotificationName:
+ CommIOSNotificationsRegistrationFailed
+ object:self
+ userInfo:errorInfo];
+ }];
+}
+
+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:21 PM (21 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2497820
Default Alt Text
D6070.id21009.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