iOS 分享微信朋友圈


    官网地址: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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值