Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33311162
D6070.1768810266.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D6070.1768810266.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
Mon, Jan 19, 8:11 AM (20 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5955335
Default Alt Text
D6070.1768810266.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