美文网首页
极光RN插件可修改角标(android)

极光RN插件可修改角标(android)

作者: Blue_Color | 来源:发表于2024-01-02 14:27 被阅读0次

项目使用的版本是

"jcore-react-native": "^1.9.5",
"jpush-react-native": "^2.8.7",
"react": "17.0.1",
"react-native": "0.64.4"

在react native项目中找到node_modules中的jpush-react-native:
1.修改jpush-react-native中的index.js中的setBadge方法

image.png
    // static setBadge(params) {
    //     if (Platform.OS == "ios") {
    //         JPushModule.setBadge(params)
    //     }
    // }

    static setBadge(params) {
        if (Platform.OS == "ios") {
            JPushModule.setBadge(params)
        }else if (Platform.OS == "android") {
            JPushModule.setBadgeNumber(params)
        }
    }

2.修改jpush-react-native中android文件夹下的cn.jiguang.plugins.push.common.JConstants类添加一个常量


image.png
public static final String BADGE_NUMBER = "badge";

3.修改jpush-react-native中android文件夹下JPushModule类添加一个方法


image.png
    @ReactMethod
    public void setBadgeNumber(ReadableMap readableMap) {
        if (readableMap == null) {
            JLogger.w(JConstants.PARAMS_NULL);
            return;
        }
        if (readableMap.hasKey(JConstants.BADGE_NUMBER)) {
            int number = readableMap.getInt(JConstants.BADGE_NUMBER);
            JPushInterface.setBadgeNumber(reactContext,number);
        } else {
            JLogger.w("there are no " + JConstants.BADGE_NUMBER);
        }
    }

至此,修改完毕。

相关文章

网友评论

      本文标题:极光RN插件可修改角标(android)

      本文链接:https://www.haomeiwen.com/subject/iabbcdtx.html