Ich verwende Firebase Cloud Messaging in meiner App. Es funktionierte für ein paar Wochen gut, aber diese letzten zwei Tage tut es nicht.Firebase Push-Benachrichtigung funktioniert nicht nach ein paar Wochen
Ich sende die Nachrichten von der Firebase-Konsole. Ich handle mit der Token-Aktualisierung. Was kann das Problem sein? mein Code
Dies ist:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[self registerForPush];
}
Hier ist, wo ich für Push-Benachrichtigungen registrieren:
-(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];
}
für Remote-Benachrichtigungen mit dem Geräte-Token Hat registrieren:
- (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];
}
}
dies der Observer für das Token zum Aktualisieren der 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];
}
}
das ist mein abonniere Feuerbasis Themen:
-(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
}