Я интегрирую уведомление FCM и облачные сообщения в своем приложении. Я выполнил точно такие же шаги, упомянутые в документе firebase. Даже я попытался с примером кода, данным FCM. он просто бросает некоторые предупреждения как <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "The operation couldn’t be completed. and <FIRMessaging/WARNING> FIRMessaging registration is not ready with auth credentials.
Уведомление FCM не работает в ios
Может кто-нибудь помочь мне разобраться. Я занимаюсь поиском в Интернете с одной недели, но ничего полезного я не получил. Мой код написан в Appdelegate.m is
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Register for remote notifications
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
// iOS 7.1 or earlier
UIRemoteNotificationType allNotificationTypes =
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge);
[application registerForRemoteNotificationTypes:allNotificationTypes];
} else {
// iOS 8 or later
// [END_EXCLUDE]
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
// [START configure_firebase]
[FIRApp configure];
// [END configure_firebase]
// Add observer for InstanceID token refresh callback.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:)
name:kFIRInstanceIDTokenRefreshNotification object:nil];
return YES;
}
// [START receive_message]
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// Print message ID.
NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);
// Pring full message.
NSLog(@"%@", userInfo);
}
// [END receive_message]
// [START refresh_token]
- (void)tokenRefreshNotification:(NSNotification *)notification {
// Note that this callback will be fired everytime a new token is generated, including the first
// time. So if you need to retrieve the token as soon as it is available this is where that
// should be done.
NSString *refreshedToken = [[FIRInstanceID instanceID] token];
NSLog(@"InstanceID token: %@", refreshedToken);
// Connect to FCM since connection may have failed when attempted before having a token.
[self connectToFcm];
// TODO: If necessary send token to appliation server.
}
// [END refresh_token]
// [START connect_to_fcm]
- (void)connectToFcm {
[[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Unable to connect to FCM. %@", error);
} else {
NSLog(@"Connected to FCM.");
}
}];
}
// [END connect_to_fcm]
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self connectToFcm];
}
// [START disconnect_from_fcm]
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[FIRMessaging messaging] disconnect];
NSLog(@"Disconnected from FCM");
}
// [END disconnect_from_fcm]
Надежда, чтобы получить ответ в ближайшее время. Спасибо заранее!
Как вы отправляете сообщения? Используете консоль firebase и настраиваете таргетинг на все устройства? Вы добавили GoogleService-Info.plist? Вы также можете попробовать выполнить приложение: didFailToRegisterForRemoteNotificationsWithError для получения дополнительной информации – Chris
Я отправляю сообщения через консоль firebase (уведомление), и я добавил googleService-Info.plist. didFailtoRegister не получает вызов. я получаю токен устройства, но не уведомляю об устройстве – ios
и yaa, я нацелен на одно устройство, а также помещаю маркер регистрации FCM в требуемое поле. В консоли firebase состояние сообщения завершено, но нет push-уведомления на устройстве. Я проверил с обоими состояниями, то есть с приложением в фоновом режиме и переднем плане. – ios