npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-rich-notification

v1.0.7

Published

集成Android各厂商推送服务,只支持Android端使用

Downloads

25

Readme

react-native-rich-notification

集成各Android厂商的推送服务,仅支持Android端使用;

| 厂商 | 接入SDK | RN端封装 | | :--: | :-----: | :------: | | 华为 | ✓ | ✓ | | oppo | ✓ | ✓ | | 魅族 | ✓ | — | | 荣耀 | ✓ | — | | 小米 | — | — | | vivo | — | — | 目前在自己项目进行调试,会在近期陆续完善,有问题可联系[email protected]

注:小米需要app上线后才可接入其推送服务

安装

$ npm install react-native-rich-notification --save

React Native link

react native <= 0.59.x 需手动 link

$ react-native link react-native-rich-notification

手动配置

通知栏消息配置

MainActivity中做如下修改

import com.doubleyolk.richnotification.MessageHandler;// add this
import com.facebook.react.ReactInstanceManager;// add this

public class MainActivity extends ReactActivity {

  private static MessageHandler messageHandler;// add this
  private ReactInstanceManager mReactInstanceManager;// add this

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    messageHandler = new MessageHandler();//add this
    getIntentData(getIntent());//add this
		initMessageHandler();// add this
  }

  @Override
  public void onNewIntent(Intent intent){
    super.onNewIntent(intent);
    setIntent(intent);// add this
    getIntentData(intent);// add this
  }
  
  // add this
  public void initMessageHandler(){
    mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
    if (null == mReactInstanceManager.getCurrentReactContext()) {
      mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
        @Override
        public void onReactContextInitialized(ReactContext context) {
          messageHandler.initMessageHandler(context);
          mReactInstanceManager.removeReactInstanceEventListener(this);
        }
      });
    }else{
      ReactContext context  =  mReactInstanceManager.getCurrentReactContext();
      messageHandler.initMessageHandler(context);
    }
  }

  // add this
  private void getIntentData(Intent intent) {
    this.messageHandler.HandleIntent(intent);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
  }
}

华为

  1. 按官方的Android接入文档进行以下步骤:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/android-config-agc-0000001050170137

    1. 配置AppGallery Connect
    2. 集成HMS Core SDK
    3. 配置混淆脚本
  2. android/app/AndroidManifest.xml 添加

    <!-- 华为推送桌面角标权限 -->
        <uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
       
    <service android:name="com.doubleyolk.richnotification.HwPushService" android:exported="false">
        <intent-filter>
            <action android:name="com.huawei.push.action.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    <meta-data
        android:name="push_kit_auto_init_enabled"
        android:value="false" />

OPPO

  1. 按官方文档进行配置: https://open.oppomobile.com/new/developmentDoc/info?id=11221

  2. android/app/AndroidManifest.xml 修改为**"com.doubleyolk.richnotification.OppoPushService"**

    <service
        android:name="com.doubleyolk.richnotification.OppoPushService"
        android:permission="com.heytap.mcs.permission.SEND_PUSH_MESSAGE"
        android:exported="true">
        <intent-filter>
            <action android:name="com.heytap.mcs.action.RECEIVE_MCS_MESSAGE"/>
            <action android:name="com.heytap.msp.push.RECEIVE_MCS_MESSAGE"/>
        </intent-filter>
    </service>

使用

import RichNotification, {
  InitPushConfig,
} from 'react-native-rich-notification';
import {
  Platform,
} from 'react-native';

const App = ()=>{
  
  //各平台所需的配置参数
  const initConfig: InitPushConfig = {
    oppo: {
      appKey: 'xxxxx',
      appSecret: 'xxxxx',
    },
    meizu: {appId: 'xxxxx', appSecret: 'xxxxx'},
  };
  
  useEffect(()=>{
    if(Platform.OS === "android"){
      //初始化推送服务,必须先初始化再调用其它方法
			RichNotification.initPush(initConfig, (res: initPushCallback) => {
        //获取设备注册ID
        RichNotification.getRegisterId((res: DeviceRegisterInfo) => {
          console.warn(res.brand, res.data);
        });
      });
      
      RichNotification.addNotificationTapListener((message: any) => {
        console.warn('点击了推送消息', message);
      });
    }
  },[])
}

方法

initPush()

初始化推送服务, 必须初始化后再调用其它方法。

参数

| 参数名 | 类型 | 必填 | | ------ | -------------- | ---- | | config | InitPushConfig | true |

addNotificationTapListener()

监听点击通知栏消息事件方法,包括app杀死后点击消息打开app,回调返回消息数据,消息体中的点击行为配置项必须是唤起MainActivity

消息配置

该方法需要后台在消息体中配置点击行为参数配合

  1. 华为

    {click_action : 3}

  2. oppo :

    {click_action_type:4, click_action_activity:"com.example.MainActivity"}

    com.example.MainActivity替换成你的MainActivity

参数

| 参数名 | 类型 | 必填 | | -------- | -------- | ----- | | callback | function | false |

RichNotification.addNotificationTapListener((message: any) => {
  console.warn('点击了推送消息', message);
});

addHuaweiRemoteMessageListener()

监听华为的透传消息,回调返回消息数据

参数

| 参数名 | 类型 | 必填 | | -------- | -------- | ----- | | callback | function | false |

RichNotification.addHuaweiRemoteMessageListener((message: any) => {
	console.warn('透传消息', message);
});

removeListener()

移除监听

const HwRemoteListener = RichNotification.addHuaweiRemoteMessageListener((message: any) => {
	console.warn('透传消息', message);
});

RichNotification.removeListener(HwRemoteListener)

getRegisterId()

获取设备注册ID,必须在初始化之后调用

参数

| 参数名 | 类型 | 必填 | | -------- | -------- | ----- | | callback | function | false |

RichNotification.getRegisterId((res: DeviceRegisterInfo) => {
  console.warn(res.brand, res.data);
});

setBadge()

设置桌面角标,0即清除角标, 暂只华为支持

参数

| 参数名 | 类型 | 必填 | | ------ | ------ | ---- | | badge | number | True |

type ConfigInfo = {
    appId?:string,
    appKey?:string,
    appSecret?:string
}

type InitPushConfig = {
    /**
     * 华为可不传
     */
    huawei?:ConfigInfo,
    /**
     * oppo需要appkey,appsecret
     */
    oppo?:ConfigInfo,
    /**
     * 魅族需要appid,appsecret
     */
    meizu?:ConfigInfo,
    /**
     * 荣耀不用传,需要在AndroidManifest.xml配置appid即可
     */
    honor?:ConfigInfo,
    vivo?:ConfigInfo,
    mi?:ConfigInfo,
}