php - iOS 静默远程推送通知不起作用:没有用户可见的内容
问题描述
我正在尝试将静默远程推送通知从 PHP 服务器发送到 iOS 设备。使用https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app上的信息进行设置
当我发送消息时,我可以看到 iOS 设备(iOS 版本 12.4.7)正在接收它。但我也可以看到一个错误“通知没有用户可见的内容”。现在这是一个无声的背景通知,并且设置了标题apns-push-type:background
,我认为不需要用户可见的内容?
[xxxxx] Not delivering user visible push notification B026-EC8D [ error=Error Domain=UNErrorDomain Code=1401 "Notification has no user visible content" UserInfo={NSLocalizedDescription=Notification has no user visible content} ]
通知在应用程序处于后台模式时有效,但在应用程序关闭时无效。
我已尝试发送正常的非背景警报,即使应用程序已关闭,它也能正常工作。
下面是我为测试创建的一个简单的类/函数
class SimpleApnsService
{
public static function push($deviceToken, $certificate, $topic)
{
$payload = '{
"appdata": "command:refresh",
"aps": {
"content-available": 1
}
}';
$url = "https://api.development.push.apple.com/3/device/$deviceToken";
$headers = [
"apns-topic:$topic",
"apns-push-type:background",
"apns-priority:5",
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// there is not password set on the certificate
curl_setopt($ch, CURLOPT_SSLCERT, $certificate);
// return true
$response = curl_exec($ch); => return true
// returns 200
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
}
解决方案
推荐阅读
- python - 在 python 中替换 UTF-8 编码的 Twitter 表情符号
- python - 如何从高斯分布中制作戒指
- scala - 在scala中调用map函数的不同方式
- java - 解组 XML Java JAXB
- javascript - 如何对未登录的用户隐藏我的大部分 JavaScript?
- php - Spatie/Newsletter:Laravel 5.6 中提供的 MailChimp 无效的 MailChimp API 密钥
- opencart - 从opencart中的表单获取数据
- .htaccess - 使用子域重写 url 返回“无法访问此站点”
- php - Wordpress 如何使用 qTranslateX 插件以编程方式更新特定语言的帖子名称
- sql-server - 如何直接从表中为 sp_executesql 分配参数值?