本文介绍了推送通知后的离子设置徽章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 IONIC 框架,我想在获得推送通知后设置应用程序的徽章。

I'm using IONIC Framework and I'd like to set the badge of my application after I'm getting push notification.

当我的申请被关闭时,有办法吗?

Is there a way to do it when my application is closed?

推荐答案

它适用于其他人会遇到同样的问题。
我相信你所说的是用你从服务器收到的更新的徽章编号可以看到徽章。

it is for others who will run into the same problem.I believe your talking about making badge visible with the updated badge number you've received from server.

首先在init方法的代码中启用它像这样推送

First thing to enable it in code in init method of Push like this

var push = PushNotification.init({
                android: {
                    senderID: senderID,
                    icon: 'pushicon',
                    sound: "true",
                    iconColor: "#ED8B00"
                },
                browser: {
                    pushServiceURL: 'url'
                },
                ios: {
                    alert: "true",
                    **badge: "true",**
                    sound: "true"
                },
                windows: {}
            });

在上面的代码中,我们启用了徽章{将在所有iPhone和支持的Android手机中显示}

In above code we've enabled badge {will be displayed in all iPhones and supported Android Phones as well}

现在从服务器端。
将以下部分添加到您的ios部分,这样即使您的应用程序处于后台也会获得更新计数。

Now from server side.add below part to your ios portion so will get the updatd count even your your app is in background.

这仅适用于ios,请为Android添加根据您的要求;

This is for ios only, please add for android as per your requirements;

 {
    "aps": {
        "alert": {
            "title": "Received",
            "body": "You have received a message from Kens"
        },
        "badge": 66
    },
    "received_id": "9223",
    "pn_type": "RECEIVED"
}

此徽章计数将自动更新为应用程序徽章数量,即使应用程序位于后台。(但徽章字段应为整数)。

This badge count will automatically get updated to apps badge count even app is in background.(but badge field should be in integer).

谢谢希望这一点帮助解决您的问题。

Thanks hope this helps and solve your problem.

这篇关于推送通知后的离子设置徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 19:42