1.下载SDK包,然后拖入项目中
2.导入对应的库
3.在Xcode中,填写你所注册的微信应用程序id(如下图所示),此步为配置应用间的跳转
4.就说明没有针对iOS9 增加白名单。在info.plist文件中加入 LSApplicationQueriesSchemes (只写item0,item1).
#import "WXApi.h"
@interface LoginViewController ()<WXApiDelegate>
- (void)viewDidLoad {
[superviewDidLoad];
[[NSNotificationCenterdefaultCenter] addObserver:self
selector:@selector(WeiXinRegisterAndLogin)
name:@"weixin"
object:nil];
- (IBAction)weixinButtonClick:(id)sender {
if ([WXApiisWXAppInstalled]) {//判断手机上是否有微信
if ([WXApiisWXAppSupportApi]) {//判断当前的微信版本是否支持注册登录
//构造SendAuthReq结构体,
SendAuthReq *req = [[SendAuthReqalloc] init];
req.scope =@"snsapi_message,snsapi_userinfo,snsapi_friend,snsapi_contact";
req.state =@"wechat";
req.openID=weixinAppid;
[WXApisendReq:req];
}else{
UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"温馨提示"message:@"当前微信版本过低,请先升级"preferredStyle