首页 > 解决方案 > 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);
    }
}

标签: phpiosapple-push-notifications

解决方案


推荐阅读