Skip to content

Instantly share code, notes, and snippets.

@skoch
Created October 21, 2016 20:06
Show Gist options
  • Save skoch/1d7bc4c7eabe83c16abb354fe0969a4a to your computer and use it in GitHub Desktop.
Save skoch/1d7bc4c7eabe83c16abb354fe0969a4a to your computer and use it in GitHub Desktop.
Firebase initialization and register for remote notifications
[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