想要的效果
分享的SDK我是集成的友盟,具體的集成請看友盟官方文檔或其他帖子,這里只寫怎么實現(xiàn)的方法
//分享按鈕響應(yīng)事件
-(void)shareBtnClick{
__weak typeof(self) weakSelf = self;
//顯示分享面板
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMShareMenuSelectionView *shareSelectionView, UMSocialPlatformType platformType) {
// [weakSelf disMissShareMenuView:shareSelectionView];
[weakSelf shareTextToPlatformType:platformType];
}];
}
//設(shè)置友盟分享內(nèi)容
- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType
{
//創(chuàng)建分享消息對象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
NSString * titleName = @"我在洋主播里看直播";
NSString * strFullUrl = @"www.baidu.com";
UIImage * image = [UIImage imageNamed:@"about"];
//這里需要注意苗分,新浪的url和QQ,微信等不一樣牵辣,需要分別處理摔癣,還有設(shè)置的文本(titleName),url地址(strFullUrl),圖片(image)都不能為空纬向,必須要有值
if (platformType==UMSocialPlatformType_Sina) { //新浪的分享
//設(shè)置文本
messageObject.text= [NSString stringWithFormat:@"%@,%@",titleName,strFullUrl];
//創(chuàng)建圖片內(nèi)容對象
UMShareImageObject*shareObject = [[UMShareImageObject alloc]init];
//如果有縮略圖择浊,則設(shè)置縮略圖
shareObject.shareImage= image;
//分享消息對象設(shè)置分享內(nèi)容對象
messageObject.shareObject= shareObject;
}else{ //QQ、QQ空間逾条、微信琢岩、朋友圈等分享
//[[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:dict[@"image"]]]]
UMShareWebpageObject * shareObject = [UMShareWebpageObject shareObjectWithTitle:titleName descr:nil thumImage:image];
shareObject.webpageUrl= strFullUrl;
//分享消息對象設(shè)置分享內(nèi)容對象
messageObject.shareObject= shareObject;
}
//調(diào)用分享接口
[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
if (error) {
NSLog(@"************Share fail with error %@*********",error);
}else{
NSLog(@"response data is %@",data);
}
}];
}
其實這種類似于名片的分享就是一個url地址,點擊這種名片就能進(jìn)入到網(wǎng)頁中师脂。
點關(guān)注担孔,不迷路