@yrobotit/react-native-wechat-login
v0.1.2
Published
WeChat login module for React Native
Maintainers
Readme
react-native-wechat-login
wechat login
Installation
# yarn
yarn add @yrobotit/react-native-wechat-login
cd ios && pod install
# npm
npm install @yrobotit/react-native-wechat-login
cd ios && pod installUsage
import { registerApp, addAuthListener, sendAuthRequest, isWXAppInstalled } from '@yrobotit/react-native-wechat-login';
useEffect(() => {
registerApp('你的微信APPID', Platform.OS === 'ios' ? 'https://your.domain/ulink/' : null);
const remove = addAuthListener(({ code, errCode, state }) => {
if (errCode === 0 && code) {
// fetch token from your backend with 'code'
}
});
return () => remove();
}, []);
const onPressWeChat = async () => {
if (await isWXAppInstalled()) sendAuthRequest('snsapi_userinfo', 'rn');
};#pragma mark - appDelegate.mm 微信回调转发(这2个方法必须保留)
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary *)options
{
return [WeChatLoginModule handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
return [WeChatLoginModule handleUniversalLink:userActivity];
}Contributing
License
MIT
Made with create-react-native-library
