微信SDK集成示例,现已完成微信授权登录,之后将陆续包装分享等其他功能。
ReactNative高级交流群 127482131 或访问 http://blog.1ygowu.com ReactNative技术专题
$ npm i react-native-wechat-ios
参考 https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content
$(SRCROOT)/../../react-native/React
,并选择recursive
。$(SRCROOT)/../node_modules/react-native-wechat-ios/RCTWeChat
,并选择recursive
。
Xcode7 可能找不到*.dylib库,解决方法参考这里 http://www.jianshu.com/p/1f575e4d1033
需要导入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]; }
finishedAuth
事件获取授权结果授权成功后由Native端触发该事件,通知React Native端。
import {NativeAppEventEmitter} from 'react-native'; NativeAppEventEmitter.addListener( 'finishedAuth', (response) => AlertIOS.alert(JSON.stringify(response)) );
response.code
response.state
response.errCode
import WeChat from 'react-native-wechat-ios'; let state = '1311231'; WeChat.sendAuthRequest(state, (res) => { });
// 向微信注册应用ID WeChat.registerApp('你的微信应用ID', (res) => { alert(res); // true or false });
WeChat.isWXAppInstalled((res) => { alert('isWXAppInstalled: '+res); // true or false });
let state = '1311231'; WeChat.sendAuthRequest(state, (res) => { });
记得要将 AppDelegate.m 文件中的IP换成自己的:
jsCodeLocation = [NSURL URLWithString:@"http://172.16.5.70:8081/index.ios.bundle?platform=ios&dev=true"];
react-native-wechat-ios
微信SDK集成示例,现已完成微信认证登录,分享链接功能。
react-native-wechat-android
react-native 的微信SDK辅助包,支持微信登录、微信分享、微信支付。
ReactNative高级交流群 127482131 或访问 http://blog.1ygowu.com ReactNative技术专题
转(前端乱炖) (http://www.html-js.com/article/3330)