友盟分享
1、引入头文件
#import <UMSocialCore/UMSocialCore.h>
#import <UShareUI/UShareUI.h>
2、遵循协议
<UMSocialPlatformProvider,UMSocialShareMenuViewDelegate>
3、开始分享
分为两种情况:一是系统自带的分享面板,二是自定义分享面板。
使用友盟系统自带的分享面板:
-(void)shareAction{
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_WechatTimeLine)]];
[UMSocialUIManager setShareMenuViewDelegate:self];
// [UMSocialUIUtility configWithPlatformType:UMSocialPlatformType_QQ withImageName:nil withPlatformName:nil];
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
// 根据获取的platformType确定所选平台进行下一步操作
[self shareToPlatformType:platformType];
}];
}
自己写的:
自定义分享平台面板
可以不使用友盟自带的分享到平台到显示面板:
[UMSocialUIManager removeAllCustomPlatformWithoutFilted];
不写上面shareAction
方法里面的代码,就是不使用友盟自带的样式。
然后自己去写一个view, 显示在window上:
[[UIApplication sharedApplication].keyWindow addSubview:shareView];
点击每个按钮分享到不同的平台上面。
例如分享到朋友圈
[self shareToPlatformType:UMSocialPlatformType_WechatTimeLine];
4、
//分享到指定平台
- (void)shareToPlatformType:(UMSocialPlatformType)platformType {
//创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//创建分享的网页
/**
* @param title 标题
* @param descr 描述
* @param thumImage 缩略图(UIImage或者NSData类型,或者image_url)
*
*/
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享到标题" descr:@"分享的描述" thumImage:[UIImage imageNamed:@"redPacketTip"]];
shareObject.webpageUrl = @"https://www.baidu.com/";
//分享消息对象设置分享内容对象
messageObject.shareObject = shareObject;
//判断是否安装所分享到的平台, 没安装则不分享,给出提示。
if (![self isInstall:platformType]) {
return ;
}
//调用分享接口
[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
;
//分享失败
if (error) {
}else{
if (platformType == UMSocialPlatformType_WechatTimeLine) {
//分享到朋友圈成功
} else {
//分享到其他平台成功
}
}
}];
}
判断是否安装分享平台
#pragma mark 判断是否安装分享平台
- (BOOL)isInstall:(UMSocialPlatformType)platformType {
if (![[UMSocialManager defaultManager] isInstall:platformType]) {
if (platformType == UMSocialPlatformType_QQ) {
//qq
NSLog(@"未安装QQ");
} else {
//weixin
}
return NO;
}
return YES;
}
网友评论