Push notification 在应用程序处于后台时,在接收ACS推送时增加应用程序徽章:钛
我的应用程序使用ACS推送通知。我已经在我的应用程序中实现了app-badge。但问题是appBadge在接收推送通知时不会自动递增。我在我的应用程序中使用了以下代码Push notification 在应用程序处于后台时,在接收ACS推送时增加应用程序徽章:钛,push-notification,titanium,titanium-mobile,acs,badge,Push Notification,Titanium,Titanium Mobile,Acs,Badge,我的应用程序使用ACS推送通知。我已经在我的应用程序中实现了app-badge。但问题是appBadge在接收推送通知时不会自动递增。我在我的应用程序中使用了以下代码 var deviceToken; Titanium.Network.registerForPushNotifications({ types: [ Titanium.Network.NOTIFICATION_TYPE_BADGE, Titanium.Network.N
var deviceToken;
Titanium.Network.registerForPushNotifications({
types: [
Titanium.Network.NOTIFICATION_TYPE_BADGE,
Titanium.Network.NOTIFICATION_TYPE_ALERT,
Titanium.Network.NOTIFICATION_TYPE_SOUND
],
success:function(e)
{
deviceToken = e.deviceToken;
SubscribeToPush(channelName, deviceToken, type);
},
error:function(e)
{
alert("Error: "+ ((e.error && e.message) || JSON.stringify(e.error)));
},
callback:function(e)
{
var badgeCount = Ti.UI.iPhone.getAppBadge();
badgeCount = badgeCount + 1;
Ti.UI.iPhone.setAppBadge(badgeCount);
}
});
我读到,在收到新的推送通知时调用。因此,我将下面的代码设置为callback以增加徽章
callback:function(e)
{
var badgeCount = Ti.UI.iPhone.getAppBadge(); //Will return the app badges
badgeCount = badgeCount + 1; //Incrementing the appbadge
Ti.UI.iPhone.setAppBadge(badgeCount); //Setting new appbadge
}
当应用程序处于打开状态时,当它收到通知时,会启动回调,当应用程序进入后台时,会出现徽章。但我想在应用程序处于后台或退出时增加徽章编号。有人能帮我解决这个问题吗?经过大量研究,我创建了一个示例应用程序,在接收服务器推送通知时增加appBadge您可以从下载代码。下载资源文件夹后,请执行以下步骤
var payload = {"alert":"Hi, This is a test notification", badge: "+1"};
/*+1 will increment the current appbadge by 1, number of appbadge will be saved in the ACS*/
Cloud.PushNotifications.notify({
channel: 'friend_request',
payload: payload
}, function (e) {
if (e.success) {
alert('Success');
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
这将使appbadge增加一个。当您恢复/打开应用程序时,需要按如下方式重置appbadge
Cloud.PushNotifications.resetBadge({
device_token : myDeviceToken
}, function(e){
if(e.success){
Ti.UI.iPhone.setAppBadge(0);
} else {
//Error callback
}
})
经过大量研究,我创建了一个示例应用程序,在接收服务器推送通知时增加appBadge您可以从下载代码。下载资源文件夹后,请执行以下步骤
var payload = {"alert":"Hi, This is a test notification", badge: "+1"};
/*+1 will increment the current appbadge by 1, number of appbadge will be saved in the ACS*/
Cloud.PushNotifications.notify({
channel: 'friend_request',
payload: payload
}, function (e) {
if (e.success) {
alert('Success');
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
这将使appbadge增加一个。当您恢复/打开应用程序时,需要按如下方式重置appbadge
Cloud.PushNotifications.resetBadge({
device_token : myDeviceToken
}, function(e){
if(e.success){
Ti.UI.iPhone.setAppBadge(0);
} else {
//Error callback
}
})
我在此处添加了一个请求:我在此处添加了一个请求: