本帖最后由 竹林风 于 2019-1-12 21:00 编辑
导读
主要代码:
[Objective-C] 纯文本查看 复制代码 UIButton *btnShare = [MTools createButtonWithTitle:@"分享" Font:kFont(18) TitleColor:kColor(orangeColor)];
btnShare.frame = CGRectMake(50, 80, ScreenWidth - 100, 50);
[btnShare addButtonClickBlock:^(UIButton *btn) {
[YNShareTool shareMessageToViewController:self title:@"分享" shareText:@"这是分享内容" url:@"https:[url=http://www.baidu.com]www.baidu.com[/url]" ThumbImage:nil];
}];
[self.view addSubview:btnShare];
相关配置
1. SDK位置
2.修改友盟Appkey 以及第三方平台的Appkey 和AppSecure
3.修改URL Types
4.调用方法封装在 YNShareTool.m
1).直接调用默认分享面版
[Objective-C] 纯文本查看 复制代码 + (void)shareMessageToViewController:(UIViewController *)viewController title:(NSString *)title shareText:(NSString *)text url:(NSString *)url ThumbImage:(id)thumbImage
{
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),
@(UMSocialPlatformType_WechatTimeLine),
@(UMSocialPlatformType_QQ),
@(UMSocialPlatformType_Qzone),
// @(UMSocialPlatformType_TencentWb),
@(UMSocialPlatformType_Sina),
]];
[UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom;
[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType = UMSocialPlatformItemViewBackgroudType_None;
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
// [self runShareWithType:platformType];
showWithText(@"分享中...");
[YNShareTool shareWithType:platformType ThumbImage:thumbImage Content:text Title:title ShareUrl:url ViewController:viewController];
}];
}
可修改需要显示的分享平台
2)分享到指定平台
[Objective-C] 纯文本查看 复制代码 //分享到指定平台
+(void)shareWithType:(NSInteger)platform ThumbImage:(id)thumbImage Content:(NSString *)shareContent Title:(NSString *)title ShareUrl:(NSString *)shareUrl ViewController:(UIViewController *)view{
//创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//创建网页内容对象
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:shareContent thumImage:thumbImage];
//设置网页地址
shareObject.webpageUrl = shareUrl;
//分享消息对象设置分享内容对象
messageObject.shareObject = shareObject;
//调用分享接口
// dismissHUD();
[[UMSocialManager defaultManager] shareToPlatform:platform messageObject:messageObject currentViewController:view completion:^(id data, NSError *error) {
dismissHUD();
if (error) {
NSLog(@"************Share fail with error %@*********",error);
// showInfoTips(@"");
}else{
// dismissHUD();
NSLog(@"share success: response data is %@",data);
}
}];
}
附件:链接:https://pan.baidu.com/s/1KmELMh8xKSE3BGIjUZv4VQ 密码:qq6b
|