@@ -196,26 +196,42 @@ void NotifyListenerSet(Listener* listener) {
196
196
LogInfo (" FCM: Using FCM senderID %s" , senderID.UTF8String );
197
197
id appDelegate = [UIApplication sharedApplication ];
198
198
199
- #if FIREBASE_PLATFORM_IOS
200
- // Register for remote notifications. Both codepaths result in
201
- // application:didRegisterForRemoteNotificationsWithDeviceToken: being called when they
202
- // complete, or application:didFailToRegisterForRemoteNotificationsWithError: if there was an
203
- // error. We complete the future there.
204
- if (floor (NSFoundationVersionNumber ) <= NSFoundationVersionNumber_iOS_7_1) {
205
- // iOS 7.1 or earlier
206
- UIRemoteNotificationType allNotificationTypes =
207
- (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert |
208
- UIRemoteNotificationTypeBadge);
209
- [appDelegate registerForRemoteNotificationTypes: allNotificationTypes];
210
- } else {
211
- // iOS 8 or later
212
- UIUserNotificationType allNotificationTypes =
213
- (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
214
- UIUserNotificationSettings *settings =
215
- [UIUserNotificationSettings settingsForTypes: allNotificationTypes categories: nil ];
216
- [appDelegate registerUserNotificationSettings: settings];
199
+ #if FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
200
+ if ([UNUserNotificationCenter class ] != nil ) {
201
+ // iOS 10 or later, and tvOS
202
+ // For iOS 10 display notification (sent via APNS)
203
+ [UNUserNotificationCenter currentNotificationCenter ].delegate = appDelegate;
204
+ UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
205
+ UNAuthorizationOptionSound | UNAuthorizationOptionBadge ;
206
+ [[UNUserNotificationCenter currentNotificationCenter ]
207
+ requestAuthorizationWithOptions: authOptions
208
+ completionHandler: ^(BOOL granted, NSError * _Nullable error) {
209
+ }];
217
210
[appDelegate registerForRemoteNotifications ];
218
211
}
212
+ #endif // FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
213
+
214
+ #if FIREBASE_PLATFORM_IOS
215
+ // Register for remote notifications. Both codepaths result in
216
+ // application:didRegisterForRemoteNotificationsWithDeviceToken: being called when they
217
+ // complete, or application:didFailToRegisterForRemoteNotificationsWithError: if there was an
218
+ // error. We complete the future there.
219
+ if (floor (NSFoundationVersionNumber ) <= NSFoundationVersionNumber_iOS_7_1) {
220
+ // iOS 7.1 or earlier
221
+ UIRemoteNotificationType allNotificationTypes =
222
+ (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert |
223
+ UIRemoteNotificationTypeBadge);
224
+ [appDelegate registerForRemoteNotificationTypes: allNotificationTypes];
225
+ } else if (floor (NSFoundationVersionNumber ) <= NSFoundationVersionNumber_iOS_9_4) {
226
+ // 8.0 <= iOS version <= 9.4
227
+ // >= 10.0 is handled by the first if block above.
228
+ UIUserNotificationType allNotificationTypes =
229
+ (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
230
+ UIUserNotificationSettings *settings =
231
+ [UIUserNotificationSettings settingsForTypes: allNotificationTypes categories: nil ];
232
+ [appDelegate registerUserNotificationSettings: settings];
233
+ [appDelegate registerForRemoteNotifications ];
234
+ }
219
235
#endif // FIREBASE_PLATFORM_IOS
220
236
221
237
// Only request the token automatically if permitted
@@ -524,11 +540,13 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
524
540
[user_notification_center setDelegate: (id <UNUserNotificationCenterDelegate >)application];
525
541
}
526
542
543
+ g_message_notification_opened = false ;
527
544
#if FIREBASE_PLATFORM_IOS
528
545
// If the app was launched with a notification, cache it until we're connected.
529
546
g_launch_notification =
530
547
[launch_options objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
531
548
g_message_notification_opened = g_launch_notification != nil ;
549
+ #endif // FIREBASE_PLATFORM_IOS
532
550
533
551
IMP app_delegate_application_did_finish_launching_with_options =
534
552
SwizzledMethodCache ().GetMethodForObject (
@@ -551,7 +569,6 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
551
569
[invocation getReturnValue: &ret];
552
570
return ret;
553
571
}
554
- #endif // FIREBASE_PLATFORM_IOS
555
572
return NO ;
556
573
}
557
574
0 commit comments