将 PushPlugin 与我的 PhoneGap 3 iOS 应用程序一起使用,我的推送通知大部分都能正常工作,但我使用自定义负载向 APNS 发送通知。它看起来像这样:
$body = array(
'customID' => $customID
);
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
根据我的阅读,这应该是由 APNS ( scroll down to the bottom ) 支持的,但是 PushPlugin's documentation根本不能很好地处理iOS。我想要的是当我的应用程序通过点击通知打开时能够将 customID
作为 JS 变量进行访问。当应用程序只是自行启动时,我不希望发生任何特别的事情。此外,用户点击哪个通知也很重要 - customID
是唯一且重要的。我真的很困惑,因为我找不到任何人谈论使用 PushPlugin 处理这些自定义 APNS 负载。
最佳答案
将自定义变量添加到推送通知有效负载的正确方法不是将其添加到 aps 命名空间(该命名空间由 Apple 保留),而是单独添加,例如:
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$body['payload'] = array(
'customID' => $customID
);
在 PhoneGap 中,您可以在通知回调(例如 onNotificationAPN)中读取它,如下所示:
function onNotificationAPN (e) {
if (e.customID)
{
navigator.notification.alert("CustomID: " + e.customID);
}
关于ios - PhoneGap PushPlugin - 访问 iOS APNS 有效负载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21917624/