第一步:RootViewController.h头文件需要引入微信SDK头文件,并继承微信处理接口
#import "WXApi.h"
@interface RootViewController : UIViewController <WXApiDelegate>{
}
第二步:由于ios系统升级的原因,9.0之后需要添加微信白名单,否则功能无法使用,也是关键一步,方法如下
Xcode 工程下打开Info,选项Custom iOS Target Properties添加Key:LSApplicationQueriesSchemes,LSApplicationQueriesSchemes里面增加选项item:weixin
第三步:代码调用
//登录微信
-(void)sendAuthRequest
{
//构造SendAuthReq结构体
SendAuthReq* req =[[[SendAuthReq alloc ] init ] autorelease ];
req.scope = @"snsapi_userinfo" ;
req.state = @"123" ;
//第三方向微信终端发送一个SendAuthReq消息结构 判断微信有没有安装
if([WXApi isWXAppInstalled])
{
[WXApi sendReq:req];
}
else
{
//[WXApi sendAuthReq:req viewController:self delegate:self];
//没有安装微信 则走账号登录
CLoadLayer::withoutWeixinClient();
}
}