【发布时间】:2020-02-09 23:28:06
【问题描述】:
我正在从 Amazon SNS 发布通知并在我的设备上正确接收它。
这是我要发送的示例消息:
{
"APNS_SANDBOX": "{\"aps\":{\"alert\":{\"title\":\"A short string describing the purpose of the notification\",\"body\":\"The text of the alert message\",\"launch-image\":\"The filename of an image file in the app bundle, with or without the filename extension. The image is used as the launch image when users tap the action button or move the action slider\"},\"badge\":5,\"content-available\":\"1\",\"category\":\"identifier\",\"thread-id\":\"id\",\"sound\":\"default\"},\"notId\":1,\"custom_key1\":\"value1\",\"custom_key2\":\"value2\"}"
}
但是,当我在手机上打开通知时,我期待 notification 事件触发,我的目标是在打开通知时向用户发送一个 url,例如:window.location='data.some_link_to_notification';
我把所有这些都去掉了,只是添加了一个警报,看看它是否被调用,但似乎没有。这是我的index.js 文件。
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
onDeviceReady: function() {
StatusBar.backgroundColorByHexString('#FFFFFF');
var push = PushNotification.init({
android: {},
browser: {},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
push.on('notification', function (data) {
alert("notification event");
});
push.on('error', function (err) {
console.log(err)
alert('Event=error, message=' + err.message)
});
push.on('registration', function (data) {
console.dir(data)
console.log('registrationId:' + data.registrationId)
window.localStorage.setItem("regId", data.registrationId);
});
cordova.InAppBrowser.open('app_url', '_self');
}
};
app.initialize();
【问题讨论】:
-
原来调用
cordova.InAppBrowser.open('app_url', '_self')会中断链接到我的cordova.js文件,所以现在所有的监听器都被中断了。使用 InAppBrowser 不是常用方法吗?
标签: ios cordova push-notification apple-push-notifications amazon-sns