当推送通知身份验证请求延迟时,Firebase Messaging不会发送通知

时间:2017-09-27 08:39:15

标签: firebase apple-push-notifications firebase-cloud-messaging

我将Firebase更新为4.2,将FirebaseMessaging更新为2.0.3,然后我的推送通知代码不再有效。

所以我尝试了quickstart项目,并发现如果我稍后请求推送通知,那么即使它似乎是正确生成的,令牌也不起作用。 (将令牌发送到FCM并获得成功消息,但推送从未进入设备)。

Firebase快速入门回购邮件是:https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExample/AppDelegate.m

然后我向用户的推送通知请求延迟了10秒:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

    // Register for remote notifications. This shows a permission dialog on first run, to
    // show the dialog at a more appropriate time move this registration accordingly.
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
        // iOS 7.1 or earlier. Disable the deprecation warnings.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        UIRemoteNotificationType allNotificationTypes =
        (UIRemoteNotificationTypeSound |
         UIRemoteNotificationTypeAlert |
         UIRemoteNotificationTypeBadge);
        [application registerForRemoteNotificationTypes:allNotificationTypes];
#pragma clang diagnostic pop
    } else {
        // iOS 8 or later
        // [START register_for_notifications]
        if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
            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
            // For iOS 10 display notification (sent via APNS)
            [UNUserNotificationCenter currentNotificationCenter].delegate = self;
            UNAuthorizationOptions authOptions =
            UNAuthorizationOptionAlert
            | UNAuthorizationOptionSound
            | UNAuthorizationOptionBadge;
            [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
            }];
#endif
        }

        [[UIApplication sharedApplication] registerForRemoteNotifications];
        // [END register_for_notifications]
    }
        });

1 个答案:

答案 0 :(得分:0)

原来2.0.3版本存在问题。 他们建议将FirebaseInstanceID降级为2.0.0

pod'FirebaseInstanceID','2.0.0'

参考: https://github.com/firebase/quickstart-ios/issues/327#issuecomment-332655731

希望这有助于某人!

相关问题