FCM дает успех, но устройство не показывает уведомление iOS - PullRequest
0 голосов
/ 23 сентября 2019

Я создал свое приложение для получения уведомлений Firebase.Я проверил это через консоль FCM, и устройство получило уведомление.Однако, когда я тестирую с testflight, устройство не получало никакого уведомления, но когда я проверял полезную нагрузку, оно показывало успех.

1. Uploaded the production .p12 certificate in firebase.
2. Capabilities -> Background Modes = ON with Remote Notifications = true; 
   PushNotifications = set to 'true'
3. In Info.plist FirebaseAppDelegateProxyEnabled = YES , 
   FirebaseScreenReportingEnable = NO

Вот мой код

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if ([UNUserNotificationCenter class] != nil) {
            // iOS 10 or later
            // 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) {

             }];
        } else {
            // iOS 10 notifications aren't available; fall back to iOS 8-9 notifications.
            UIUserNotificationType allNotificationTypes =
            (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
            UIUserNotificationSettings *settings =
            [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
            [application registerUserNotificationSettings:settings];
        }

        [application registerForRemoteNotifications];
            [FIRApp configure];
            [self connectToFcm];
        [FIRMessaging messaging].delegate = self;

            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:) name:kFIRInstanceIDTokenRefreshNotification object:nil];

}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
        [[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeSandbox];
  [FIRMessaging messaging].APNSToken = deviceToken;


}
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
    self.DeviceId=fcmToken;

    // Notify about received token.
    NSDictionary *dataDict = [NSDictionary dictionaryWithObject:fcmToken forKey:@"token"];
    [[NSNotificationCenter defaultCenter] postNotificationName:
     @"FCMToken" object:nil userInfo:dataDict];

}
- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {

    NSLog(@"%@", remoteMessage.appData);

}
- (void)tokenRefreshNotification:(NSNotification *)notification {


    [[FIRInstanceID instanceID] instanceIDWithHandler:^(FIRInstanceIDResult * _Nullable result,
                                                        NSError * _Nullable error) {
        if (error != nil) {
            NSLog(@"Error fetching remote instance ID: %@", error);
        } else {
            NSString *refreshedToken = result.token;
            self.DeviceId = refreshedToken;
            NSLog(@"InstanceID token: %@", refreshedToken);
            NSLog(@"Remote instance ID token: %@", result.token);
        }
    }];


}
- (void)connectToFcm {
    [[FIRInstanceID instanceID] instanceIDWithHandler:^(FIRInstanceIDResult * _Nullable result,
                                                        NSError * _Nullable error) {
        if (error != nil) {
            NSLog(@"Error fetching remote instance ID: %@", error);
        } else {
            NSLog(@"Remote instance ID token: %@", result.token);
        }
    }];
}

Протестировал его через restclient и получил эторезультат

{
  "multicast_id": 4659854677338425000,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    {
      "message_id": "0:1569222922386579%12eeef7ecccfb49c"
    }
  ]
}

Почему мое устройство не показывает уведомление, даже если оно успешно?

Любые идеи / помощь будут высоко оценены.

1 Ответ

1 голос
/ 23 сентября 2019

Правильно ли вы выполнили настройку «Создать ключ аутентификации»?

https://firebase.google.com/docs/cloud-messaging/ios/certs

...