iOS QQ空间 好友分享

iOS QQ空间 好友分享

1.进入腾讯开发者平台,可以查看分享SDK文档,根据说明按步骤接入

demo演示

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    btn.frame = CGRectMake(110, 100, 100, 30);

    [btn setTitle:@"QQ空间分享" forState:UIControlStateNormal];

    [self.view addSubview:btn];

    btn.backgroundColor = [UIColor redColor];

    [btn addTarget:self action:@selector(qqZoneShare) forControlEvents:UIControlEventTouchUpInside];

    

    UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeCustom];

    btnTwo.frame = CGRectMake(110, 160, 100, 30);

    [btnTwo setTitle:@"QQ好友分享" forState:UIControlStateNormal];

    [self.view addSubview:btnTwo];

    btnTwo.backgroundColor = [UIColor redColor];

    [btnTwo addTarget:self action:@selector(qqFriendShare) forControlEvents:UIControlEventTouchUpInside];

}


- (void)qqFriendShare {

    NSURL *previewURL = [NSURL URLWithString:@"http://baidu.com"];

    NSString *path = [[NSBundle mainBundle] bundlePath];

    NSString *name = [NSString stringWithFormat:@"iconname.png"];

    NSString *finalPath = [path stringByAppendingPathComponent:name];

    NSData *previeImgData = [NSData dataWithContentsOfFile:finalPath];

    QQApiNewsObject *imgObj = [QQApiNewsObject objectWithURL:previewURL title:@"分享内容的title" description:@"本宝宝是内容的描述" previewImageData:previeImgData];

    [imgObj setCflag:kQQAPICtrlFlagQQShare];

    

    

    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];

    QQApiSendResultCode sent = [QQApiInterface sendReq:req];

    [self handleSendResult:sent];

}


- (void)qqZoneShare {

    

#pragma mark--分享纯文本 success

//    QQApiTextObject *txtObj = [QQApiTextObject objectWithText:@"分享内容的text"];

#pragma mark--分享news success

//    NSURL *previewURL = [NSURL URLWithString:@"http://v.youku.com/v_show/id_XMTQ3OTM4MzMxMg==_ev_3.html?from=y1.3-idx-uhome-1519-20887.205805-205902.3-1"];

    NSURL *previewURL = [NSURL URLWithString:@"http://baidu.com"];

    NSString *path = [[NSBundle mainBundle] bundlePath];

    NSString *name = [NSString stringWithFormat:@"iconname.png"];

    NSString *finalPath = [path stringByAppendingPathComponent:name];

    NSData *previeImgData = [NSData dataWithContentsOfFile:finalPath];

    QQApiNewsObject *imgObj = [QQApiNewsObject objectWithURL:previewURL title:@"分享内容的title" description:@"本宝宝是内容的描述" previewImageData:previeImgData];

    [imgObj setCflag:kQQAPICtrlFlagQZoneShareOnStart];

   

    

    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];

    QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];

    [self handleSendResult:sent];

}



- (void)handleSendResult:(QQApiSendResultCode)sendResult {

    switch (sendResult) {

        case EQQAPIAPPNOTREGISTED:

        {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

            break;

        }

        case EQQAPIMESSAGECONTENTINVALID:

        case EQQAPIMESSAGECONTENTNULL:

        case EQQAPIMESSAGETYPEINVALID:

        {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

            

            break;

        }

        case EQQAPIQQNOTINSTALLED:

        {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

            break;

        }

        case EQQAPIQQNOTSUPPORTAPI:

        {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

            

            break;

        }

        case EQQAPISENDFAILD:

        {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

            

            break;

        }


        default:

            break;

    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值