微信SDK集成示例,现已完成微信授权登录,之后将陆续包装分享等其他功能。http://www.cnblogs.com/suxun/p/5223893.html
$ 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"];