APNS JSON PAYLOAD - 更多参数

发布于 2024-11-05 22:42:53 字数 514 浏览 1 评论 0原文

我需要向 APNS 服务的 json 负载添加一些参数。我该怎么做? 这是苹果的文档: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194- CH100-SW1

当我尝试发送带有关闭和查看按钮的消息时,我需要添加我的移动应用程序所需的两个参数。 有什么想法吗?

I need to add some arguments to a json payload for APNS service. How can i do this?
this is the documentation of apple: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1

When i try to send a message with close and view buttons, i need to add two more arguments that my mobile application needs.
Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贩梦商人 2024-11-12 22:42:53

不确定您是否得到答案。但这就是文档提到的

提供商可以指定自定义负载
Apple 保留的 aps 之外的值
命名空间。自定义值必须使用
JSON 结构化和原始类型:
字典(对象)、数组、字符串、
数字和布尔值。

因此,为了将自定义值添加到您的有效负载中,只需将它们作为键值对添加到您的有效负载中。像这样的

{
    "aps":{
        "alert":"Your Message",
        "sound":"push1.wav"
     },
     "custom_key1":"value1",
     "custom_key2":"value2"
}

这里 custom_key1custom_key2 是您的自定义键,value1value2 是它们的值。

Not sure if you got the answer yet. But this is what the documentation mentions

Providers can specify custom payload
values outside the Apple-reserved aps
namespace. Custom values must use the
JSON structured and primitive types:
dictionary (object), array, string,
number, and Boolean.

So in order to add custom values to your payload, just add them as key-value pairs in your payload. Something like this

{
    "aps":{
        "alert":"Your Message",
        "sound":"push1.wav"
     },
     "custom_key1":"value1",
     "custom_key2":"value2"
}

Here custom_key1 and custom_key2 are your custom keys and value1 and value2 are their values.

待天淡蓝洁白时 2024-11-12 22:42:53

如果有人仍然想知道:

$body = (array('aps' => array('alert' => $message,'sound' => $sound_file_wav),   "some_key" => "custom_id"));
$payload = json_encode($body);

In case someone is still wondering :

$body = (array('aps' => array('alert' => $message,'sound' => $sound_file_wav),   "some_key" => "custom_id"));
$payload = json_encode($body);
御守 2024-11-12 22:42:53

我在 PHP 中使用以下内容

$title = 'My Test Message';
$sound = 'doorbell.caf';
$msgpayload=json_encode(array('aps' => array('alert' => $title,'sound' => $sound,)));


$response = $sns->publish(array(
    'TopicArn' => $TopicArn,
    'MessageStructure' => 'json',
    'Message' => json_encode(array(
        'default' => $title,
        'APNS_SANDBOX' => $msgpayload
    ))
));

I use the following in PHP

$title = 'My Test Message';
$sound = 'doorbell.caf';
$msgpayload=json_encode(array('aps' => array('alert' => $title,'sound' => $sound,)));


$response = $sns->publish(array(
    'TopicArn' => $TopicArn,
    'MessageStructure' => 'json',
    'Message' => json_encode(array(
        'default' => $title,
        'APNS_SANDBOX' => $msgpayload
    ))
));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文