gpt4 book ai didi

ios - 几周后 Firebase 推送通知不起作用

转载 作者:行者123 更新时间:2023-11-29 11:48:59 27 4
gpt4 key购买 nike

我在我的应用中使用 Firebase 云消息传递。它在几周内运行良好,但最近两天,它没有。

我从 Firebase 控制台发送消息。我处理 token 刷新。可能是什么问题?

这是我的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[self registerForPush];
}

这是我注册推送通知的地方:

-(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];
}

是否使用设备 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];
}
}

这是 firebase 刷新 token 时的观察者:

- (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];
}
}

这是我订阅的 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
}

最佳答案

您的 APNs 证书可能由于某种原因被吊销了。尝试生成一个新的并在 firebase 控制台中重新上传它!

https://firebase.google.com/docs/notifications/ios/console-audience#upload_your_apns_certificate

关于ios - 几周后 Firebase 推送通知不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42109208/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com