代码之家  ›  专栏  ›  技术社区  ›  Andrea Gorrieri

无法接收iOS的FCM推送通知

  •  1
  • Andrea Gorrieri  · 技术社区  · 7 年前

    quick start iOS project .

    我遵循了 guide :

    使用pod安装SDK,这是我的pod文件:

    # 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 developer portal上生成APNs认证密钥和APPID(APPID由Xcode自动生成)
    • 在Firebase开发者控制台中为我的应用程序创建了一个新项目,下载并复制GoogleService信息。项目根目录中的plist文件
    • 已在Firebase开发者控制台中上载APNs身份验证密钥
    • 安装应用程序并将其置于后台(应用程序位于前台时不会显示通知)

    当应用程序启动时,它会正确返回FCM令牌。然后我在FCM推送通知控制台中使用这个令牌来发送消息,但什么也没有发生:即使控制台说消息已经“完成”,也不会收到通知 enter image description here

    尝试使用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,我想一切都没问题,但我仍然没有收到任何通知。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Andrea Gorrieri    7 年前

    问题是我忘了在“功能”选项卡的“后台模式”中添加“远程通知”。现在一切如期进行。