Handle WeChat callback events
masterWhen WeChat returns to your app (e.g., after a successful payment or returning from a Mini Program), it triggers events via DeviceEventEmitter. You should set up listeners before triggering the action that causes the return.
Listening for Responses (WeChat_Resp)
Use the WeChat_Resp event to handle results from payments, sharing, or Mini Program interactions.
Listening for Requests (WeChat_Req)
Use the WeChat_Req event to handle scenarios where the user returns from a Mini Program to your app.
Implementation Pattern:
import { DeviceEventEmitter } from 'react-native';
import * as WeChat from 'react-native-wechat-lib';
// 1. Register App
WeChat.registerApp(APP_ID, UNIVERSAL_LINK);
// 2. Setup Listeners
DeviceEventEmitter.addListener('WeChat_Req', req => {
if (req.type === 'LaunchFromWX.Req') {
// Handle return from Mini Program
}
});
DeviceEventEmitter.addListener('WeChat_Resp', resp => {
if (resp.type === 'WXLaunchMiniProgramReq.Resp') {
// Handle Mini Program response
} else if (resp.type === 'PayReq.Resp') {
// Handle Payment response
}
});