1

私のアプリでFirebase Cloud Messagingを使用しています。それは数週間はうまくいきましたが、この2日間は成功しませんでした。数週間後にFirebaseプッシュ通知が機能しない

Firebaseコンソールからメッセージを送信します。トークンのリフレッシュを処理します。何が問題なの?

これは私のコードです:私はプッシュ通知を登録するのはここ

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

は、デバイストークンとリモート通知のために登録してい:

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

これは、火災ベースのリフレッシュトークンについてのオブザーバー:

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

答えて

関連する問題