实现弹出分享框控制器代码
#import <UShareUI/UShareUI.h>
- (void)viewDidLoad {
[super viewDidLoad];
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_Sina),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_WechatSession)]];
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
// 根据获取的platformType确定所选平台进行下一步操作
}];
//设置用户自定义的平台
[UMSocialUIManager addCustomPlatformWithoutFilted:UMSocialPlatformType_UserDefine_Begin+2
withPlatformIcon:[UIImage imageNamed:@"zhongjianggonggao_xyzj"]
withPlatformName:@"复制链接"];
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_UserDefine_Begin+2),
@(UMSocialPlatformType_WechatSession),
@(UMSocialPlatformType_WechatTimeLine),
@(UMSocialPlatformType_QQ),
@(UMSocialPlatformType_Qzone),
@(UMSocialPlatformType_Sina),
]];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[button setTitle:@"页面底部菜单-1" forState:UIControlStateNormal];
button.backgroundColor=[UIColor orangeColor];
[button addTarget:self action:@selector(showBottomNormalView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)showBottomNormalView
{
// [UMSocialUIManager addCustomPlatformWithoutFilted:UMSocialPlatformType_UserDefine_Begin+2
// withPlatformIcon:[UIImage imageNamed:@"zhongjianggonggao_xyzj"]
// withPlatformName:@"复制链接"];
[UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom;
[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType = UMSocialPlatformItemViewBackgroudType_None;
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
//在回调里面获得点击的
if (platformType == UMSocialPlatformType_UserDefine_Begin+2)
{
NSLog(@"你点击了复制链接按钮");
}
else
{
[self runShareWithType:platformType];
}
}];
}
- (void)runShareWithType:(UMSocialPlatformType)type
{
// UMShareTypeViewController *VC = [[UMShareTypeViewController alloc] initWithType:type];
// [self.navigationController pushViewController:VC animated:YES];
//创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//设置文本
messageObject.text = @"哈撒给";
//调用分享接口
[[UMSocialManager defaultManager] shareToPlatform:type messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
if (error) {
UMSocialLogInfo(@"************Share fail with error %@*********",error);
}else{
if ([data isKindOfClass:[UMSocialShareResponse class]]) {
UMSocialShareResponse *resp = data;
//分享结果消息
UMSocialLogInfo(@"response message is %@",resp.message);
//第三方原始返回的数据
UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
}
else
{
UMSocialLogInfo(@"response data is %@",data);
}
}
[self alertWithError:error];
}];
}
- (void)alertWithError:(NSError *)error
{
NSString *result = nil;
if (!error) {
result = [NSString stringWithFormat:@"Share succeed"];
}
else{
NSMutableString *str = [NSMutableString string];
if (error.userInfo) {
for (NSString *key in error.userInfo) {
[str appendFormat:@"%@ = %@ ", key, error.userInfo[key]];
}
}
if (error) {
result = [NSString stringWithFormat:@"Share fail with error code: %d %@",(int)error.code, str];
}
else{
result = [NSString stringWithFormat:@"Share fail"];
}
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
message:result
delegate:nil
cancelButtonTitle:NSLocalizedString(@"sure", @"确定")
otherButtonTitles:nil];
[alert show];
}