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-oppo-push

v1.0.4

Published

[![npm version](https://img.shields.io/npm/v/react-native-oppo-push.svg)](https://www.npmjs.com/package/react-native-oppo-push) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)

Downloads

3

Readme

react-native-oppo-push

npm version PRs Welcome

react-native-oppo-push 使用 OPPO PUSH 客户端SDK接口文档(2.1.0版本),适配最新 Android 10(Android Q)的 OPPO 手机厂商推送,系统级触达,无拦截,亿级推送能力。

安装

$ yarn add react-native-oppo-push

Link

  • React Native 0.60+

CLI autolink feature 在构建应用时已自动链接此模块。

  • React Native <= 0.59
$ react-native link react-native-oppo-push

Android 配置

AndroidManifest.xml 文件中添加以下配置:

<application
    ...
    android:allowBackup="true"
    ...>
    <meta-data android:name="oppo_app_id" android:value="在 OPPO 推送平台的 AppId" />
    <meta-data android:name="oppo_app_key" android:value="在 OPPO 推送平台的 AppKey" />
    <meta-data android:name="oppo_app_secret" android:value="在 OPPO 推送平台的 AppSecret" />
    <meta-data android:name="oppo_channel_id" android:value="在 OPPO 推送平台配置的通道ID" />
    <meta-data android:name="oppo_channel_name" android:value="在 OPPO 推送平台配置的通道名称" />
    <meta-data android:name="oppo_channel_description" android:value="在 OPPO 推送平台配置的通道描述" />
    ...
</application>

Android 8.0(API ≥ 26),需要配置通道,参考 OPPO 文档

使用

import { OppoPush,
    OPPOPushEmitter,
    OT_REGISTER,
    OT_UN_REGISTER,
    OT_GET_PUSH_STATUS,
    OT_GET_NOTIFICATION_STATUS,
    OT_SET_PUSH_TIME,
    OT_ERROR } from "react-native-oppo-push";

API 和使用示例

init

初始化 OPPO PUSH 服务,创建默认通道。

定义:

init(): void

Example:

OppoPush.init();

getRegister

获取注册OPPO PUSH推送服务的注册ID

定义:

getRegister(): void

Example:

OppoPush.getRegister();

unRegister

注销注册OPPO PUSH推送服务

定义:

unRegister(): void

Example:

OppoPush.unRegister();

requestNotificationPermission

弹出通知栏权限弹窗(仅一次)

定义:

requestNotificationPermission(): void

Example:

OppoPush.requestNotificationPermission();

isSupportPush

判断手机平台是否支持 OPPO PUSH 服务

定义:

isSupportPush(): Promise

Returns:

Promise 对象。如果支持,为 true,否则为 false

Example:

OppoPush.isSupportPush().then(data => {
    console.log("【isSupportPush】" + data);
});

openNotificationSettings

打开通知栏设置界面

定义:

openNotificationSettings(): void

Example:

OppoPush.openNotificationSettings();

getPushStatus

获取 OPPO PUSH 推送服务状态

定义:

getPushStatus(): void

Example:

OppoPush.getPushStatus();

getNotificationStatus

获取通知栏状态

定义:

getNotificationStatus(): void

Example:

OppoPush.getNotificationStatus();

pausePush

暂停接收 OPPO PUSH 服务推送的消息

定义:

pausePush(): void

Example:

OppoPush.pausePush();

resumePush

恢复接收OPPO PUSH服务推送的消息,这时服务器会把暂停时期的推送消息重新推送过来

定义:

resumePush(): void

Example:

OppoPush.resumePush();

getPushVersionCode

获取OPPO PUSH推送服务MCS版本(例如"1701")

定义:

getPushVersionCode(): Promise

Returns:

包含的 OPPO PUSH 的MCS版本的 Promise 对象,例如 1701

Example:

OppoPush.getPushVersionCode().then(code => {
    console.log(code);
});

getPushVersionName

获取 OPPO PUSH 推送服务MCS名称(例如"1.7.1")

定义:

getPushVersionName(): Promise

Returns:

包含的 OPPO PUSH 的MCS名称的 Promise 对象,例如 "1.7.1"

Example:

OppoPush.getPushVersionName().then(name => {
    console.log(name);
});

getSDKVersion

获取 OPPO PUSH 推送服务SDK版本(例如"2.1.0")

定义:

getSDKVersion(): Promise

Returns:

包含的 OPPO PUSH 的 SDK 版本的 Promise 对象,例如 "2.1.0"

Example:

OppoPush.getSDKVersion().then(sdk => {
    console.log(sdk);
});

setPushTime

设置允许推送时间

定义:

setPushTime(params: object): void

Returns:

Promise 对象

Example:

let params = {
    weekDays: [0, 1, 5],    // 周日为0,周一为1,以此类推
    startHour: 0,           // 开始小时,24小时制
    startMin: 0,            // 开始分钟
    endHour: 23,            // 结束小时,24小时制
    endMin: 59              // 结束分钟
};
OppoPush.setPushTime(params).catch(error => {
    console.log(error);
});

constants

该常量用于事件订阅返回的数据类型

定义:

OT_REGISTER                     // 注册
OT_UN_REGISTER                  // 注销
OT_GET_PUSH_STATUS              // 推送状态
OT_GET_NOTIFICATION_STATUS      // 通知状态
OT_SET_PUSH_TIME                // 设置推送时间
OT_ERROR                        // 错误

OPPOPushEmitter

用于事件订阅

Example:

export default class App extends Component {
    constructor(props) {
        super(props);
        this.onOPPOPushListener = this._onOPPOPushListener.bind(this);
    }
    
    componentDidMount() {
        OPPOPushEmitter.on("OPPO_Push_Response", this.onOPPOPushListener);
    }

    componentWillUnmount() {
        OPPOPushEmitter.removeListener('OPPO_Push_Response', this.onOPPOPushListener);
    }
    
    _onOPPOPushListener(data) {
        let text = "";
        if (data != null) {
            let {code, data, status, message, type} = data;
            switch(type) {
                case OT_REGISTER:
                    if (code == 0) {
                        text = "【注册成功】registerId:" + data;
                    } else {
                        text = "【注册失败】code=" + code;
                    }
                    break;
                case OT_UN_REGISTER:
                    if (code == 0) {
                        text = "【注销成功】code=" + code;
                    } else {
                        text = "【注销失败】code=" + code;
                    }
                    break;
                case OT_GET_PUSH_STATUS:
                    if (code == 0 && status == 0) {
                        text = `【Push状态正常】code=${code},status=${status}`;
                    } else {
                        text = `【Push状态错误】code=${code},status=${status}`;
                    }
                    break;
                case OT_GET_NOTIFICATION_STATUS:
                    if (code == 0 && status == 0) {
                        text = `【通知状态正常】code=${code},status=${status}`;
                    } else {
                        text = `【通知状态错误】code=${code},status=${status}`;
                    }
                    break;
                case OT_SET_PUSH_TIME:
                    text = `【SetPushTime】code=${code},result:${data}`;
                    break;
                case OT_ERROR:
                    text = message;
                    break;
            }
        }
        console.log(text);
    }
}

Demo

  • Demo 代码参考 example

  • 安卓手机也可以直接下载并安装已编译的 apk