ios - iPhone X 上未收到 Firebase 通知 FCM
问题描述
(Xcode 9 / Swift 4)
我有一个用于Firebase Cloud Messaging
接收的 iOS 应用程序silent push notifications
该应用程序已发布,但 iPhone X 用户未收到通知
我已经对所有内容进行了三次检查,所有内容都是最新的,包括 Google PodsFirebaseMessaging (3.0.2)
我的生成静默推送通知的服务器应用程序 (c#) 也在使用最新版本的Google APIs (1.34)
因此,使用生成通知的应用程序来测试 iPhone 是否收到通知,我得到了以下结果:
- 连接 Xcode 的 iPhone 6S 收到通知
- iPhone 6S 运行 testflight 版本收到通知
- iPhone 6S 运行应用商店版收到通知
- 连接到 Xcode 的 iPhone X 收到通知
- iPhone X 运行 testflight 版本收不到
- iPhone X 运行 app store 版本收不到
这是最糟糕的部分......如果我从 c# 应用程序中获取 iPhone X 令牌并通过 Firebase 控制台发送一条消息,它将被 testflight 版本接收(我想这证明我要发送的令牌是正确一个)
我知道我没有提供代码,但实际上没有什么要检查的......一切都在 iPhone 6S 上运行良好,甚至在连接到 Xcode 的 iPhone X 上运行良好。
我在想不知何故我的服务器 IP 地址无法从 iPhone X 访问,但事实并非如此,因为在应用程序启动期间我连接到服务器并下载数据没有问题......就像 iPhone X 有某种防火墙阻止来自我的 IP 的传入消息?即使我知道我在 iPhone X 上拥有应用通知权限(我可以从 Firebase 控制台发送消息),我还是在应用内创建了一个日志屏幕,并且知道该权限已启用。
我错过了什么吗???是否需要为 iPhone X 启用我不知道的其他权限?
编辑: iPhoneX iOS 版本 = 11.4
EDIT2:似乎,由于某种原因,iPhone X 需要包含有效负载"notification: {"title":"xxx", "body":"xxx"}"
,这是没有意义的,因为 iPhone 6S 可以在没有添加有效负载的情况下接收静默推送通知......现在的问题是向有效负载添加“通知”将让iOS在收到通知后立即在托盘上显示通知,女巫击败了我想要传递的“静默”通知的目的。
这是之前在 iPhone X 上不工作但在 iPhone 6S 上工作的有效载荷(FCM 负责添加content-available
标签):
{"message": {"token" : "eANw_OLOKXc:APA.....XsMg", "data" : {"content" : "2546|N|495....arg|BATTERY|||||"}}}
这是适用于 iPhone X 但会弹出系统通知的那个,我不想要:
{"message": {"token" : "eANw_OLOKXc:APA.....XsMg", "notification":{"title":"xxx","body":"xxx"},"data" : {"content" : "2546|N|495....arg|BATTERY|||||"}}}
为什么 iPhone 6S 可以在没有notification
负载的情况下工作?以及如何向 iPhone X 发送静音通知
编辑 3:我想唯一的选择是开始一个新项目并复制问题,因为我被卡住了......我不明白为什么通过运行与 Xcode 绑定的项目使其在 iPhone X 中运行但在没有运行时插入的 USB 数据线不会收到通知。我忘了提到 iPhone 6S 也在 iOS 11.4 上
编辑 4:当无声通知到达时,我设法直接从 iPhone X 获取一些日志:
Jun 26 01:08:46 MP apsd[9726] <Notice>: APSMessageStore - APSIncomingMessageRecordDeleteMessageForGUID <private>
Jun 26 01:08:46 MP SpringBoard(UserNotificationsServer)[9680] <Notice>: Received incoming message on topic com.mydomain.myapp2 at priority 1
Jun 26 01:08:46 MP SpringBoard(UserNotificationsServer)[9680] <Notice>: [com.mydomain.myapp2] Received remote notification request C752-66DA [ hasAlertContent: 0, hasSound: 0 hasBadge: 0 hasContentAvailable: 1 hasMutableContent: 0 ]
Jun 26 01:08:46 MP SpringBoard(UserNotificationsServer)[9680] <Notice>: [com.mydomain.myapp2] Deliver push notification request C752-66DA
Jun 26 01:08:46 MP SpringBoard(UserNotificationsServer)[9680] <Notice>: [com.mydomain.myapp2] Passing content-available push to Duet
Jun 26 01:08:46 MP SpringBoard(DuetActivityScheduler)[9680] <Notice>: SUBMITTING: <private>
Jun 26 01:08:46 MP SpringBoard(UserNotificationsServer)[9680] <Error>: Ignoring notification with no alert, sound or badge (com.mydomain.myapp2): C752-66DA
Jun 26 01:08:46 MP SpringBoard(UserNotificationsServer)[9680] <Notice>: [com.mydomain.myapp2] Not saving push notification C752-66DA to store [ error=Error Domain=UNErrorDomain Code=1401 "Notification has no user-facing content" UserInfo={NSLocalizedDescription=Notification has no user-facing content} ]
Jun 26 01:08:46 MP dasd(DuetActivitySchedulerDaemon)[9752] <Notice>: Submitted Activity: com.apple.pushLaunch.com.mydomain.myapp2:2AD94B <private>
Jun 26 01:08:46 MP dasd(DuetActivitySchedulerDaemon)[9752] <Notice>: Daemon Canceling Activities: {(
com.apple.pushLaunch.com.mydomain.myapp2:2AD94B
)}
Jun 26 01:08:46 MP dasd(DuetActivitySchedulerDaemon)[9752] <Notice>: CANCELED: com.apple.pushLaunch.com.mydomain.myapp2:2AD94B <private>!
因此,iOS 似乎收到了通知以及数据(hasContentAvailable: 1
),但它没有将其发送到我的应用程序......
另外,为什么会出现这个错误:<Error>: Ignoring notification with no alert, sound or badge
...无声通知没有警报/声音/徽章!
解决方案
我有类似的问题。我将优先级设置为高并添加了以下有效负载。
let message = {
notification: {
title: 'title',
body: `title`
}
};
let options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
到目前为止它工作正常。
推荐阅读
- r - 检测大写单词的 Stringr 模式
- python - 'with ...as..' 下载图片 selenium
- r - 如何在 R 中获得随机森林中的 Brier 分数?
- c# - 有没有办法对使用 svcutil 生成的客户端代理进行版本控制?
- javascript - 如何忽略异步函数中不可用的 API 数据?
- github - GitHub 上的 SemVer 和 0.xy 版本
- c# - 创建从排序数组开始的排序顺序子数组的数组
- jenkins - Jenkins - 当某些测试失败时构建总是不稳定的,即使它必须失败
- sql - 数据库表是否应该尽可能接近地反映 API 响应?
- r - 多级模型的模型公式,其中不同的预测变量集用于随机截距和随机斜率