@@ -196,26 +196,58 @@ 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
199
+ #if FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
200
200
// Register for remote notifications. Both codepaths result in
201
201
// application:didRegisterForRemoteNotificationsWithDeviceToken: being called when they
202
202
// complete, or application:didFailToRegisterForRemoteNotificationsWithError: if there was an
203
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];
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];
217
+ // [appDelegate registerForRemoteNotifications];
218
+ // }
219
+
220
+ if ([UNUserNotificationCenter class ] != nil ) {
221
+ // iOS 10 or later, and tvOS
222
+ // For iOS 10 display notification (sent via APNS)
223
+ [UNUserNotificationCenter currentNotificationCenter ].delegate = appDelegate;
224
+ UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
225
+ UNAuthorizationOptionSound | UNAuthorizationOptionBadge ;
226
+ [[UNUserNotificationCenter currentNotificationCenter ]
227
+ requestAuthorizationWithOptions: authOptions
228
+ completionHandler: ^(BOOL granted, NSError * _Nullable error) {
229
+ // ...
230
+ }];
217
231
[appDelegate registerForRemoteNotifications ];
218
232
}
233
+ #endif
234
+
235
+ #if FIREBASE_PLATFORM_IOS
236
+ if (floor (NSFoundationVersionNumber ) <= NSFoundationVersionNumber_iOS_7_1) {
237
+ // iOS 7.1 or earlier
238
+ UIRemoteNotificationType allNotificationTypes =
239
+ (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert |
240
+ UIRemoteNotificationTypeBadge);
241
+ [appDelegate registerForRemoteNotificationTypes: allNotificationTypes];
242
+ } else if (floor (NSFoundationVersionNumber ) <= NSFoundationVersionNumber_iOS_10_0) {
243
+ // iOS 8 or later
244
+ UIUserNotificationType allNotificationTypes =
245
+ (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
246
+ UIUserNotificationSettings *settings =
247
+ [UIUserNotificationSettings settingsForTypes: allNotificationTypes categories: nil ];
248
+ [appDelegate registerUserNotificationSettings: settings];
249
+ [appDelegate registerForRemoteNotifications ];
250
+ }
219
251
#endif // FIREBASE_PLATFORM_IOS
220
252
221
253
// Only request the token automatically if permitted
@@ -524,11 +556,13 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
524
556
[user_notification_center setDelegate: (id <UNUserNotificationCenterDelegate >)application];
525
557
}
526
558
527
- #if FIREBASE_PLATFORM_IOS
528
559
// If the app was launched with a notification, cache it until we're connected.
560
+ g_message_notification_opened = false ;
561
+ #if FIREBASE_PLATFORM_IOS
529
562
g_launch_notification =
530
563
[launch_options objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
531
564
g_message_notification_opened = g_launch_notification != nil ;
565
+ #endif
532
566
533
567
IMP app_delegate_application_did_finish_launching_with_options =
534
568
SwizzledMethodCache ().GetMethodForObject (
@@ -551,7 +585,6 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
551
585
[invocation getReturnValue: &ret];
552
586
return ret;
553
587
}
554
- #endif // FIREBASE_PLATFORM_IOS
555
588
return NO ;
556
589
}
557
590
0 commit comments