当推送通知认证请求被延迟时,Firebase消息传送不发送通知
问题描述:
我将Firebase更新为4.2,FirebaseMessaging更新为2.0.3,然后我的推送通知代码不再有效。当推送通知认证请求被延迟时,Firebase消息传送不发送通知
所以我尝试了快速启动项目,并发现如果我稍后请求推送通知,即使它看起来正常生成,令牌也不起作用。 (将令牌发送给FCM并获得成功消息,但推送从未传递到设备)。
的火力地堡快速启动回购是:
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]
}
});
答
原来存在如下问题:与2.0.3构建:https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExample/AppDelegate.m
然后我以10秒添加延迟以用于从用户推送通知的请求。 他们建议降级FirebaseInstanceID到2.0.0
荚 'FirebaseInstanceID', '2.0.0'
参考: https://github.com/firebase/quickstart-ios/issues/327#issuecomment-332655731
希望这可以帮助别人!