From 971ab0b71c3b001039c0f5df68b34fd29f5b1193 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Wed, 1 Jun 2016 10:30:58 -0400 Subject: [PATCH] port notificationIOS request permission function --- ios/RNFIRMesssaging.m | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/ios/RNFIRMesssaging.m b/ios/RNFIRMesssaging.m index 29b3e00..04ae918 100644 --- a/ios/RNFIRMesssaging.m +++ b/ios/RNFIRMesssaging.m @@ -92,26 +92,20 @@ RCT_REMAP_METHOD(getFCMToken, RCT_EXPORT_METHOD(requestPermissions) { - if (RCTRunningInAppExtension()) { - return; - } - - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) { - // iOS 7.1 or earlier - UIRemoteNotificationType allNotificationTypes = - (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge); - [[UIApplication sharedApplication] registerForRemoteNotificationTypes:allNotificationTypes]; - } else { - // iOS 8 or later - // [END_EXCLUDE] - UIUserNotificationType allNotificationTypes = - (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); - UIUserNotificationSettings *settings = - [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; - [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; - [[UIApplication sharedApplication] registerForRemoteNotifications]; - } - + if (RCTRunningInAppExtension()) { + return; + } + + UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound; + + UIApplication *app = RCTSharedApplication(); + if ([app respondsToSelector:@selector(registerUserNotificationSettings:)]) { + UIUserNotificationSettings *notificationSettings = + [UIUserNotificationSettings settingsForTypes:(NSUInteger)types categories:nil]; + [app registerUserNotificationSettings:notificationSettings]; + } else { + [app registerForRemoteNotificationTypes:(NSUInteger)types]; + } } - (void)handleRemoteNotificationReceived:(NSNotification *)notification -- 2.26.2