如何在Apple推送通知上添加隐藏数据

时间:2013-07-31 02:56:45

标签: javascript cordova push-notification phonegap-build

我正在使用这个Ruby脚本发送推送通知:

APNS.host = 'gateway.push.apple.com' 
APNS.port = 2195 
APNS.pem  = 'CERTIFICATE_PATH
APNS.pass = '56895689aA'
device_token = TOKEN
APNS.send_notification(device_token, :alert => 'Message', :badge => 1, :sound =>     'beep.wav')

我正在从这样的设备(它的Phonegap)处理它

onAPNNotification: function (event) {
    var pushNotification = window.plugins.pushNotification;
    if (event.alert) {
        navigator.notification.alert(event.alert);
    }
    if (event.badge) {
        console.log("Set badge on  " + pushNotification);
        pushNotification.setApplicationIconBadgeNumber(this.onGCMRegisterSuccess, event.badge);
    }
    if (event.sound) {
        var snd = new Media(event.sound);
        snd.play();
    }
}

一切正常,我收到通知,但我想知道是否有隐藏数据,以便在通知到达时不会显示(并显示通知中包含一些文字的警报)。 / p>

任何帮助都会被贬低。

1 个答案:

答案 0 :(得分:1)

示例中的有效负载使用aps字典来请求设备显示警告消息,左侧是“关闭”按钮,警报右侧显示“操作”按钮的本地化标题。在这种情况下,“PLAY”用作当前所选语言的Localizable.strings文件中的键,以获得“Play”的本地化等效项。 aps字典还请求使用数字5标记应用程序图标。

{
"aps" : {
    "alert" : {
        "body" : "Bob wants to play poker",
        "action-loc-key" : "PLAY"
    },
    "badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang",  "whiz" ]
}

了解更多信息:Apple Dev