FCM通知在ios中不起作用

我正在将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.

任何人都可以帮我理清它。 我一个星期以来一直在Google上search,但没有任何帮助,我得到了。 我写在Appdelegate.m的代码是

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

希望很快得到答复。 提前致谢!

如果您希望在应用程序处于后台时显示通知,则需要将“优先级”设置为“高”:

当应用程序closures时,Firebase IOS推送通知不起作用

我正在做我的iOS应用程序的同样的事情。 FCM和GCM不适用于iOS。 不pipe有人说什么都没有可能。 我花了两个星期,到网上到处寻找一个post。 iOS将只接受APNS推送通知。 保存你的头痛,并开始与应用程序。

编辑:这是FCM的最新存储库。 给这个镜头,看看它是什么。 https://github.com/firebase/quickstart-ios这似乎有点不同于我在我的iOS版本上工作时所尝试的&#x3002; @Chris,这是你用来实现你的版本的代码分支吗?

我也有同样的问题。 我得到“连接到FCM”的消息和令牌,似乎一切完美,但无法收到任何通知。

但是,我立即收到通知,但之后没有任何代码更改和证书更改或删除,我无法收到任何进一步的通知。

检查我的代码,这是一个cocos2d应用程序。

 func didLoadFromCCB() { ... setupPushNotification() } func setupPushNotification () { let application = UIApplication.sharedApplication() // Register for remote notifications if #available(iOS 8.0, *) { let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) application.registerUserNotificationSettings(settings) application.registerForRemoteNotifications() } else { // Fallback let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound] application.registerForRemoteNotificationTypes(types) } FIRApp.configure() // Add observer for InstanceID token refresh callback. NSNotificationCenter.defaultCenter().addObserver(self, selector: "tokenRefreshNotification:", name: kFIRInstanceIDTokenRefreshNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive:", name: UIApplicationDidBecomeActiveNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground:", name: UIApplicationDidEnterBackgroundNotification, object: nil) } // [START refresh_token] func tokenRefreshNotification(notification: NSNotification) { let refreshedToken = FIRInstanceID.instanceID().token()! print("InstanceID token: \(refreshedToken)") // Connect to FCM since connection may have failed when attempted before having a token. connectToFcm() } // [END refresh_token] // [START connect_to_fcm] func connectToFcm() { FIRMessaging.messaging().connectWithCompletion { (error) in if (error != nil) { print("Unable to connect with FCM. \(error)") } else { print("Connected to FCM.") } } } // [END connect_to_fcm] func didBecomeActive(application:UIApplication) { NSLog("Did Become Active") connectToFcm() } func didEnterBackground(application: UIApplication) { NSLog("Did enter background") FIRMessaging.messaging().disconnect() NSLog("Disconnected from FCM.") } } 

我不知道如何得到那只有一个正确的通知,然后转换表。 🙁

让我知道如何解决这个问题。

尝试发送这个

 curl --header "Authorization: key={YOUR_API_KEY}" --header Content-Type:"application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"{YOUR_DEVICE_TOKEN}\",\"content_available\":true,\"priority\":\"high\",\"notification\":{\"title\":\"TEST\",\"sound\":\"default\",\"body\":\"IT WORKS!\",\"badge\":1}}" 

这个对我有用。 (显然,首先注册推送通知,然后打印设备令牌)