OPPO PUSH for React Native
react-native-oppo-push is developed with the official document OPPO PUSH client SDK interface documentation (version 2.1.0). It is compatible with the latest Android 10 (Android Q) OPPO mobile phone manufacturer push, system-level touch, no interception, and billion-level push capability.
Install
yarn add react-native-oppo-pushReact Native <= 0.59
react-native link react-native-oppo-pushIn AndroidManifest.xml, add the following code.
<application
...
android:allowBackup="true"
...>
<meta-data android:name="oppo_app_id" android:value="Your AppId" />
<meta-data android:name="oppo_app_key" android:value="Your AppKey" />
<meta-data android:name="oppo_app_secret" android:value="Your AppSecret" />
<meta-data android:name="oppo_channel_id" android:value="Your Channel ID" />
<meta-data android:name="oppo_channel_name" android:value="Your Channel Name" />
<meta-data android:name="oppo_channel_description" android:value="Your Channel Desc" />
...
</application>For Android 8.0 (API ≥ 26), you need to configure the channel, refer to the OPPO document.
Api
Import
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";Methods of the OppoPush
initInitialize the OPPO PUSH service and create a default channel.
getRegisterGet the registration ID of OPPO PUSH service.
unRegisterUnregister OPPO PUSH service.
requestNotificationPermissionPop-up window requesting notification permission (only once).
isSupportPushCheck if the mobile supports OPPO PUSH service.
openNotificationSettingsGoto the notification setting page.
getPushStatusGet OPPO PUSH service status.
getNotificationStatusGet notification status.
pausePushPause receiving messages pushed by OPPO PUSH service.
resumePushResume receiving messages pushed by OPPO PUSH service. Then the OPPO PUSH service will re-push the messages during the pause period.
getPushVersionCodeGet the MCS version of OPPO PUSH service (eg "1701").
getPushVersionNameGet the MCS name of the OPPO PUSH service (eg "1.7.1").
getSDKVersionGet the OPPO PUSH service SDK version (eg "2.1.0").
setPushTimeSet allow push time.
Constans
OT_REGISTEROT_UN_REGISTEROT_GET_PUSH_STATUSOT_GET_NOTIFICATION_STATUSOT_SET_PUSH_TIMEOT_ERROR
OPPOPushEmitter
OPPOPushEmitter is for event subscription.
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 = "[Register success] registerId:" + data;
} else {
text = "[Register fail] code=" + code;
}
break;
case OT_UN_REGISTER:
if (code == 0) {
text = "[Unregister success] code=" + code;
} else {
text = "[Unregister fail] code=" + code;
}
break;
case OT_GET_PUSH_STATUS:
if (code == 0 && status == 0) {
text = `[Push status is ok] code=${code},status=${status}`;
} else {
text = `[Push status is error]code=${code},status=${status}`;
}
break;
case OT_GET_NOTIFICATION_STATUS:
if (code == 0 && status == 0) {
text = `[Notification status is ok] code=${code},status=${status}`;
} else {
text = `[Notification status is error] 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
Refer to Example project.
Android phones can download and install the apk.