首页 > 解决方案 > 如何将带有 NotificationPusher 组件的自定义有效负载参数发送到苹果设备?

问题描述

我正在努力使用NotificationPusher组件以及将有效负载中的自定义参数发送到苹果产品的可能性。

我尝试了以下方法,因为我在 github 上的文档中找到了这个注释。

$message = new Message("Hello there", [
    'message' => [
        'sound' => 'default'
    ],
    'custom' => [
        'lat' => 123,
        'lon' => 321,
        'radius' => 32,
        'date' => date('Y-m-d H:i:s'),
        'action' => 'update'
    ]
]);

遗憾的是,这种语法并没有导致预期的结果。苹果设备不会收到这些参数。

我也试过这个,但这也失败了。

$message = new Message("Hello there", [
    'message' => [
        'sound' => 'default',
        'custom_lat' => 123,
        'custom_lon' => 321,
        'custom_radius' => 32,
        'custom_date' => date('Y-m-d H:i:s'),
        'custom_action' => 'update'
    ]
]);

将有效负载中的自定义参数通过推送消息发送到苹果设备的确切语法是什么?

标签: phppush-notificationapple-push-notifications

解决方案


我已经在 github 上挖掘了源代码,发现数组的“自定义”键不是由 ASPN 适配器提取的。

但是我找到了一段提取完整“消息”数组的代码,所以我的猜测是在“消息”部分中添加“自定义”数组,这也是我的问题的解决方案。

$message = new Message("Hello there", [
    'message' => [
        'sound' => 'default',
        'custom' => [
            'lat' => 123,
            'lon' => 321,
            'radius' => 32,
            'date' => date('Y-m-d H:i:s'),
            'action' => 'update'
        ]
    ]
]);

推荐阅读