我试图根据我从本教程中学到的内容,通过azure移动服务向iOS设备发送一些数据https://github.com/ggailey777/mobile-services-samples/tree/master/CordovaNotificationsArticle,
但是,当我像这样设置有效负载时
var payload = '{ "message" : "' + message + '", "title" : "Title...", "id" : "' + recordid + '" }';
只有Android设备可以在Cordova推送插件通知事件中接收其他数据,但在iOS上,未定义data.message以外的任何内容。
push.on('notification', function (data) {
var recordID = data.additionalData.id
});
这是我的注册代码:
var push = PushNotification.init({
"android": { "senderID": AzureMobileServiceClient.senderID },
"ios": { "alert": true, "badge": true, "sound": true }
});
push.on('registration', function (data) {
//// Call mobile service client here
var mobileServiceClient = new WindowsAzure.MobileServiceClient(AzureMobileServiceClient.API_URL, AzureMobileServiceClient.API_KEY);
// Get the native platform of the device.
var platform = "";
if (ionic.Platform.isIOS()) {
platform = "iOS";
}
else {
platform = "android";
}
var tags = [userid, platform];
// Get the handle returned during registration.
var handle = data.registrationId;
// Set the device-specific message template.
if (platform == "android" || platform == "Android") {
// Template registration.
var template = '{ "data" : {"message":"$(message)", "id": "$(id)", "title": "$(title)"}}';
// Register for notifications.
mobileServiceClient.push.gcm.registerTemplate(handle,
"myTemplate", template, null, tags)
.done(registrationSuccess, registrationFailure);
} else if (platform == "iOS") {
// Template registration.
var template = '{"aps": {"alert": "$(message)"}}';
// Register for notifications.
mobileServiceClient.push.apns.registerTemplate(handle,
"myTemplate", template, null, tags)
.done(registrationSuccess, registrationFailure);
}
});
有谁知道如何在iOS上获取其他数据?非常感谢任何帮助。
谢谢!
答案 0 :(得分:1)
iOS客户端应用注册的模板如下:
{"aps": {"alert": "$(message)"}}