React-Native的微信SDK辅助包,支持微信登录、微信分享、微信支付
2017-06-17 20:49
537 查看
如何安装
1. 下载包文件
$ npm i react-native-wechat-ios
2. 链接库文件到你的项目中
参考 https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content给RCTWeChat添加头文件搜索路径:
$(SRCROOT)/../../react-native/React,并选择
recursive。
因为需要在 AppDelegate.m 文件中导入 RCTWeChat.h,所以需要在你的项目中添加一个头文件搜索路径:
$(SRCROOT)/../node_modules/react-native-wechat-ios/RCTWeChat,并选择
recursive。
根据微信SDK要求需要添加以下库文件
[x] SystemConfiguration.framework
[x] libz.dylib
[x] libsqlite3.0.dylib
[x] libc++.dylib
[x] CoreTelephony.framework
Xcode7 可能找不到*.dylib库,解决方法参考这里 http://www.jianshu.com/p/1f575e4d1033
如何使用
1. 重写AppDelegate的handleOpenURL和openURL方法:
需要导入RCTWeChat.h
#import "RCTWeChat.h"
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [[RCTWeChat shareInstance] handleOpenURL: url]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [[RCTWeChat shareInstance] handleOpenURL: url]; }
2. 订阅finishedAuth
事件获取授权结果
授权成功后由Native端触发该事件,通知React Native端。import {NativeAppEventEmitter} from 'react-native'; NativeAppEventEmitter.addListener( 'finishedAuth', (response) => AlertIOS.alert(JSON.stringify(response)) );
返回值(response):
response.code
response.state
response.errCode
3. 发起授权
import WeChat from 'react-native-wechat-ios'; let state = '1311231'; WeChat.sendAuthRequest(state, (res) => { });
已完成的方法
registerApp 向微信注册应用ID// 向微信注册应用ID WeChat.registerApp('你的微信应用ID', (res) => { alert(res); // true or false });
isWXAppInstalled 检测是否已经安装微信客户端
WeChat.isWXAppInstalled((res) => { alert('isWXAppInstalled: '+res); // true or false });
sendAuthRequest 发起授权请求
let state = '1311231'; WeChat.sendAuthRequest(state, (res) => { });
Example
记得要将 AppDelegate.m 文件中的IP换成自己的:jsCodeLocation = [NSURL URLWithString:@"http://172.16.5.70:8081/index.ios.bundle?platform=ios&dev=true"];
相关文章推荐
- React Native绑定微信分享/登录/支付(演示+实现步骤+注意事项)
- 微信分享sdk 提示: 登录游戏的微信帐号与当前微信帐号不一致,是否继续
- 微信QQ第三方登录分享和支付宝微信支付
- React-Native之微信好友、朋友圈分享、支付
- React-Native之微信好友、朋友圈分享、支付
- React Native系列——微信分享
- Unity使用Share-SDK接微信登录和分享的总结(Android)
- React-Native之微信好友、朋友圈分享、支付
- Android应用之——微信微博第三方sdk登录分享使用过程中的一些常见问题
- React-Native之微信好友、朋友圈分享、支付
- React Native 接入微博、微信、QQ 登录功能
- React-Native之微信好友、朋友圈分享、支付
- React-Native之微信好友、朋友圈分享、支付
- 微信JS-SDK说明文档 能调用微信扫一扫 ,那能不能让浏览器支持微信支付呢
- 快速集成 react-native 的微信分享
- Android应用之——微信微博第三方sdk登录分享使用过程中的一些常见问题
- React Native实现微信好友/朋友圈分享功能-Android/iOS双平台通用
- 【转】react-native-wechat--微信登录
- React-Native之微信好友、朋友圈分享、支付
- React-Native之微信好友、朋友圈分享、支付