gpt4 book ai didi

android - 如何对 ionic 推送通知设置操作

转载 作者:行者123 更新时间:2023-11-30 01:17:09 24 4
gpt4 key购买 nike

我已经使用 ionic 实现了一个 android 应用程序。我想通过接受和拒绝等操作来实现推送通知。我使用 phonegap pluginpush 来推送通知。

enter image description here

但是当我点击它们时没有任何反应。

已发送通知

POST /push/notifications HTTP/1.1
Host: api.ionic.io
Content-Type: application/json
Authorization: Bearer xxxxxxxxxxxxxx


{
"tokens": ["token1","token2"],
"profile": "profile",
"notification": {
"title": "data updated ",
"message":"allow sync immediatly",
"android": {
"data": {
"image": "www/img/icon.png",
"vibrationPattern": [100, 1000, 500, 500],
"notId": 121,
"actions": [
{ "title": "Approve ", "callback": "accept", "foreground": true},
{ "title": "Reject", "callback": "reject", "foreground": true}
]
}
}
}

}

javascript

angular.module('app')

.factory("notificationService", function ($http, $q, $ionicPlatform, baseUrl, $ionicPush, $localStorage, USER) {

window.approve = function(data){ alert("Approve Triggered"); }
window.reject = function(data){ alert("Reject Triggred"); }

var notification = function () {

$ionicPlatform.ready(function () {

$ionicPush.init({
"debug": true,
"onNotification": function (notification) {
alert("notification received");
var payload = notification.payload;
},
"onRegister": function (data) {
saveGcmToken(USER.parentId(), data);
},
"pluginConfig": {
"android": {
"badge": true,
"sound": true,
"alert": true,
"icon": "icon",
'forceShow' : true,
//"iconColor": "#948438"
},
"ios": {
"badge": true,
"sound": true,
"forceShow" : true,
"alert": true

}
}
});
$ionicPush.register({
canShowAlert: true,
canSetBadge: true,
canPlaySound: true,
canRunActionsOnWake: true,
});
});
}

function saveGcmToken(parentId, token) {

var data = {};

angular.extend(data, {
id: parentId,
name: token._token
});

$http({
method: 'PUT',
contentType: 'application/json',
data: data,
url: baseUrl + "/add-app-token"
}).success(function (response) {
alert("response from notification service" + JSON.stringify(response));
}).error(function (response) {
alert("Error " + JSON.stringify(response));
});

}

return {
notification: notification
}

})

最佳答案

尝试更新您的警报功能。

"onNotification": function (notification) {
alert('message = '+notification.message+' title = '+notification.title + ' actions = '+notification.android.data.actions+ ' notId = '+notification.android.data.notId);
}

详情请访问:http://devgirl.org/2013/07/17/tutorial-implement-push-notifications-in-your-phonegap-application/

https://www.npmjs.com/package/phonegap-plugin-push-pgb

关于android - 如何对 ionic 推送通知设置操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37681612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com