无法接收iOS的FCM推送通知 [英] Can't receive FCM Push Notifications for iOS

查看:580
本文介绍了无法接收iOS的FCM推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Firebase Cloud Messaging(FCM)SDK将推送通知发送到iOS设备.我创建了一个非常简单的应用程序,该应用程序具有一个空的ViewController和一个由

I'm trying to use the Firebase Cloud Messaging (FCM) SDK to send push notification to iOS devices. I created a very simple application which has an empty ViewController and an AppDelegate copied by that provided in the quick start iOS project.

我遵循了指南中提供的所有说明:

I followed all the instructions provided in the guide:

使用pod安装了SDK,这是我的podFile:

Installed SDK using pod, here is my podFile:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

pod 'Firebase/Core'
pod 'Firebase/Messaging'

target 'fcmPushTest' do
# Comment the next line if you're not using Swift and don't want to use 
dynamic frameworks
use_frameworks!

# Pods for fcmPushTest

end

  • 在Xcode的功能"标签中添加了推送通知
  • 在Apple开发人员门户上生成的APNs身份验证密钥和APPID(APPID由Xcode自动生成)
  • 在Firebase开发人员控制台中为我的应用程序创建了一个新项目,下载并复制了项目根目录中的GoogleService-Info.plist文件
  • 在Firebase开发者控制台中上载了APNs身份验证密钥
  • 安装了应用程序并将其置于后台(当应用程序处于前台时通知不会出现)
    • Added the push notification in the "Capabilities" Tab in Xcode
    • Generated APNs authentication key and APPID (the APPID was automatically generated by Xcode) on the apple developer portal
    • Created a new project for my application in the Firebase developer console, downloading and copying the GoogleService-Info.plist file in the root directory of the project
    • Uploaded the APNs authentication key in the Firebase developer console
    • Installed the app and put it in background (notifications do not appear when app is in foreground)
    • 应用程序启动时,将正确返回FCM令牌.然后,我在FCM推送通知控制台中使用此令牌以发送消息,但没有任何反应:即使控制台说消息已完成",也不会收到通知.

      When the application starts, it correctly returns an FCM token. Then I use this token in the FCM push notification console in order to send a message but nothing happens: notification is not received even if the console says that the message has been "completed"

      尝试发送带有curl的通知

      Trying to send the notification with curl

      curl -X POST --header "Authorization: key=<API_ACCESS_KEY>" \
      --Header "Content-Type: application/json" \
      https://fcm.googleapis.com/fcm/send \
      -d "{\"to\":\"<YOUR_DEVICE_ID_TOKEN>\",\"notification\":{\"body\":\"Yellow\"},\"priority\":10}"
      

      我收到以下答复:

      {"multicast_id":7144776975498650143,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1510221288971805%7fe9e2a37fe9e2a3"}]}
      

      既然成功等于1,我想一切都很好,但是我仍然没有收到通知.

      Since success is equal to 1 i guess that all is ok but I still get no notifications.

      我用谷歌搜索了问题的可能原因,但似乎Firebase Messaging Libraries最近已更改(pod说我正在使用FirebaseMessaging 2.0.3版本),所以我找不到合适的解决方案.

      I googled for a possibile cause of the problem but it seems that Firebase Messaging Libraries have been recently changed (pod says I'm using the FirebaseMessaging 2.0.3 version) so i can't find a proper solution.

      推荐答案

      问题是我忘记在功能"选项卡的背景模式"中添加远程通知".现在一切正常.

      The problem was I forgot to add "Remote notification" in the "Background Modes" in the "Capabilities" tab. Now it's all working as expected.

      这篇关于无法接收iOS的FCM推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆