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;
? ? }
}
總結
以上是生活随笔為你收集整理的iOS QQ空间 好友分享的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国传统色彩名录
- 下一篇: 你想去看电影吗?电影院的未来可能会很像苹