[英]Firebase push notification doesn't work after a few weeks
I am using Firebase Cloud Messaging in my app.我在我的应用中使用 Firebase Cloud Messaging。 It worked fine for a few weeks, but these last two days, it doesn't.它工作了几个星期,但最近两天,它没有。
I send the messages from the Firebase Console.我从 Firebase 控制台发送消息。 I handle the token refresh.我处理令牌刷新。 What can be the problem?可能是什么问题?
This is my code:这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[self registerForPush];
}
Here is where I register for Push Notifications:这是我注册推送通知的地方:
-(void)registerForPush
{
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
UNAuthorizationOptions authOptions =
UNAuthorizationOptionAlert
| UNAuthorizationOptionSound
| UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if (error)
{
NSLog(@"\n\n %@ \n\n",error.description);
}
NSLog(@"");
}];
// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// For iOS 10 data message (sent via FCM)
[FIRMessaging messaging].remoteMessageDelegate = self;
#endif
}
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
Did register for Remote Notifications with Device Token:是否使用设备令牌注册了远程通知:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *token = [[FIRInstanceID instanceID] token];
NSLog(@"%@", token);
// Add observer to listen for the token refresh notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onTokenRefresh) name:kFIRInstanceIDTokenRefreshNotification object:nil];
if(token)
{
[self subscribeToTopics];
}
}
this the Observer for when firebase refresh token :这是 firebase 刷新令牌时的观察者:
- (void)onTokenRefresh
{
// Get the default token if the earlier default token was nil. If the we already
// had a default token most likely this will be nil too. But that is OK we just
// wait for another notification of this type.
NSString *token = [[FIRInstanceID instanceID] token];
if (token)
{
[self subscribeToTopics];
}
}
this is my subscribe to firebase topics :这是我订阅的 firebase 主题:
-(void)subscribeToTopics
{
[[FIRMessaging messaging] subscribeToTopic:@"/topics/ios"];
[[FIRMessaging messaging] subscribeToTopic:@"/topics/all"];
#ifdef DEBUG
[[FIRMessaging messaging] subscribeToTopic:@"/topics/developer_devices"];
#else
[[FIRMessaging messaging] unsubscribeFromTopic:@"/topics/developer_devices"];
#endif
}
Your APNs certificate has probably been revoked for some reason.您的 APNs 证书可能因某种原因被吊销。 Try generating a new one and re-uploading it in the firebase console!尝试生成一个新的并在 firebase 控制台中重新上传它!
https://firebase.google.com/docs/notifications/ios/console-audience#upload_your_apns_certificate https://firebase.google.com/docs/notifications/ios/console-audience#upload_your_apns_certificate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.