jpush / jpush/jpush-react-native

addReceiveNotificationListener回调无法返回正确值

Open
#621 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.4k
Forks
348
PR merge metrics
No merged PRs in 30d

Description

你的运行环境

macos android

  • 插件版本: version "2.5.3"
  • react-native 版本:"react-native": "0.59.4"

componentDidMount()中执行以下代码

    JPushModule.addReceiveNotificationListener(val => console.log(val));
    JPushModule.sendLocalNotification({
      id: 5,
      buildId: 1234,
      content: 'content',
      extra: { key1: 'value1', key2: 'value2' },
      fireTime: new Date().getTime() + 2000,
      badge: 8,
      sound: 'fasdfa',
      subtitle: 'subtitle',
      title: 'title'
    });

期望效果

{ extras: '{"key1":"value1","key2":"value2"}',
      alertContent: 'content',
      id: 5 }

实际效果

cn.jpush.android.EXTRA

如果我修改源码,

private static void sendEvent() {
        if (mEvent != null) {
            Logger.i(TAG, "Sending event : " + mEvent);
            switch (mEvent) {
                case RECEIVE_CUSTOM_MESSAGE:
                    WritableMap map = Arguments.createMap();
                    map.putInt("id", mCachedBundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID));
                    map.putString("message", mCachedBundle.getString(JPushInterface.EXTRA_MESSAGE));
                    map.putString("content", mCachedBundle.getString(JPushInterface.EXTRA_MESSAGE));
                    map.putString("content_type", mCachedBundle.getString(JPushInterface.EXTRA_CONTENT_TYPE));
                    map.putString("title", mCachedBundle.getString(JPushInterface.EXTRA_TITLE));
                    map.putString("extras", mCachedBundle.getString(JPushInterface.EXTRA_EXTRA));
                    mRAC.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                            .emit(mEvent, map);
                    break;
                case RECEIVE_NOTIFICATION:
                case OPEN_NOTIFICATION:
                    map = Arguments.createMap();
                    map.putInt("id", mCachedBundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID));
                    map.putString("alertContent", mCachedBundle.getString(JPushInterface.EXTRA_ALERT));
                    map.putString("extras", mCachedBundle.getString(JPushInterface.EXTRA_EXTRA));
                    // 添加下面这句无用的代码
                    WritableMap anything = Arguments.createMap();
                    mRAC.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                            .emit(mEvent, map);
                    break;
            }

            mEvent = null;
            mCachedBundle = null;
        }

之后就能正常返回

重现步骤

如上

Debug logs

包括 Android 或 iOS 的日志:

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Android sendEvent() implementation shown in the issue and trace the RECEIVE_NOTIFICATION event emitted to addReceiveNotificationListener. Reproduce the local notification with React Native 0.59.4 and plugin 2.5.3, then compare the callback fields with the expected object. Done means the listener returns the notification id, alert content, and extras without the reported value.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, react-native
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.