Created
October 21, 2016 20:06
-
-
Save skoch/1d7bc4c7eabe83c16abb354fe0969a4a to your computer and use it in GitHub Desktop.
Firebase initialization and register for remote notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FIRApp configure]; | |
if( floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max ) | |
{ | |
// iOS 9 | |
UIUserNotificationType allNotificationTypes = ( UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge ); | |
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; | |
[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; | |
}else | |
{ | |
// iOS 10 or later | |
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 | |
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge; | |
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) { | |
}]; | |
// For iOS 10 display notification (sent via APNS) | |
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; | |
// For iOS 10 data message (sent via FCM) | |
[[FIRMessaging messaging] setRemoteMessageDelegate:self]; | |
#endif | |
} | |
[[UIApplication sharedApplication] registerForRemoteNotifications]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment