官网地址:https://open.weixin.qq.com/cgi-bin/frame?t=home/app_tmpl&lang=zh_CN
1. 下载微信sdk,将libWeChatSDK.a,WXApi.h,WXApiObject.h 三个文件拖入工程中
2. 查看build Settings 中的 Libary Search Paths 中是否链接到了wechat
3. 在工程的info.list文件中的URL type“添加“URL scheme”为你所注册的应用程序id,效果图如下
4. 在你需要使 用微信终端API的文件中import WXApi.h 头文件,并增加 WXApiDelegate 协议
在appDelegate.h文件中
#import "WXApi.h"
@interface AppDelegate : BeeUIApplication<WXApiDelegate>
在appDelegate.m中
在didFinishLaunchingWithOptions 注册微信:
[WXApi registerApp:@"" withDescription:@""];
在下面这个方法中调用handleOpenURL方法,否则微信起不来
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL isSuc = [WXApi handleOpenURL:url delegate:self];
NSLog(@"url %@ isSuc %d",url,isSuc == YES ? 1 : 0);
return isSuc;
}
//微信分享成功后调用
-(void) onResp:(BaseResp*)resp
{
if([resp isKindOfClass:[SendMessageToWXResp class]])
{
// NSString *strTitle = [NSString stringWithFormat:@"发送媒体消息结果"];
// NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode];
if(resp.errCode == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"分享成功" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"分享失败,请重新分享" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
} }
}
5. 具体分享的代码可以查看官方的demo