// // HYUMShareManager.m // JIZHANG // // Created by jikaipeng on 2017/10/23. // Copyright © 2017年 kuxuan. All rights reserved. // #import "HYUMShareManager.h" #import @implementation HYUMShareManager + (instancetype)shareInstance{ static HYUMShareManager *shareManger = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ if (shareManger == nil) { shareManger = [[HYUMShareManager alloc]init]; } }); return shareManger; } - (void)setUMShare{ /* 打开日志 */ [[UMSocialManager defaultManager] openLog:NO]; // 打开图片水印 //[UMSocialGlobal shareInstance].isUsingWaterMark = YES; [UMSocialGlobal shareInstance].isClearCacheWhenGetUserInfo = NO; /* 设置友盟appkey setUmSocialAppkey */ [[UMSocialManager defaultManager] setUmSocialAppkey:UMAPP_KEY]; [self configUSharePlatforms]; [self confitUShareSettings]; } - (void)shareWithUI{ [UMSocialShareUIConfig shareInstance].shareTitleViewConfig.isShow = NO; [UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom; [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxRowCountForPortraitAndBottom = 2; [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxColumnCountForPortraitAndBottom = 2; // [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxRowCountForLandscapeAndMid = 2; // [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxColumnCountForLandscapeAndMid = 6; //显示分享面板 [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) { NSString *shareUrl =@"http://www.baidu.com"; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; // 根据获取的platformType确定所选平台进行下一步操作 [self shareWebPagewithplatformType:platformType title:app_Name desc:@"专业备孕、怀孕、育儿助手工具,百万怀孕妈妈的选择!" thumImageUrl:@"" webpageUrl:shareUrl]; }]; } - (void)alertWithError:(NSError *)error { NSString *result = nil; if (!error) { // result = [NSString stringWithFormat:@"分享成功"]; [SVProgressHUD showSuccessWithStatus:@"分享成功!"]; } else{ NSMutableString *str = [NSMutableString string]; if (error.userInfo) { for (NSString *key in error.userInfo) { [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]]; } } if (error) { result = [NSString stringWithFormat:@"Share fail with error code: %d\n%@",(int)error.code, str]; // [MBProgressHUD showError:result]; } else{ // result = [NSString stringWithFormat:@"Share fail"]; [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"分享失败"]; } } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share" message:result delegate:nil cancelButtonTitle:NSLocalizedString(@"sure", @"确定") otherButtonTitles:nil]; [alert show]; } - (void)configUSharePlatforms{ /* 设置微信的appKey和appSecret [微信平台从U-Share 4/5升级说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1 */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WX_APPID appSecret:WX_APP_SECRET redirectURL:nil]; /* 设置分享到QQ互联的appID * U-Share SDK为了兼容大部分平台命名,统一用appKey和appSecret进行参数设置,而QQ平台仅需将appID作为U-Share的appKey参数传进即可。 100424468.no permission of union id [QQ/QZone平台集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_3 */ // [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:QQ_APPKEY/*设置QQ平台的appID*/ appSecret:nil redirectURL:nil]; /* * 移除相应平台的分享,如微信收藏 */ [[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite),@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Tim)]]; } - (void)confitUShareSettings{ /* * 打开图片水印 */ //[UMSocialGlobal shareInstance].isUsingWaterMark = YES; /* * 关闭强制验证https,可允许http图片分享,但需要在info.plist设置安全域名 NSAppTransportSecurity NSAllowsArbitraryLoads */ //[UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO; } - (void)shareText:(NSString *)text{ UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; messageObject.text = text; [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) { NSString *message = nil; if (!error) { message = [NSString stringWithFormat:@"分享成功"]; } else { message = [NSString stringWithFormat:@"失败原因Code: %d\n",(int)error.code]; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share" message:message delegate:nil cancelButtonTitle:NSLocalizedString(@"确定", nil) otherButtonTitles:nil]; [alert show]; }]; } - (void)shareWebPagewithplatformType:(UMSocialPlatformType)platformType title:(NSString *)title desc:(NSString *)desc thumImageUrl:(NSString *)imageUrl webpageUrl:(NSString *)webUrl{ //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //创建网页内容对象 UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]]]; //设置网页地址 shareObject.webpageUrl = webUrl; //分享消息对象设置分享内容对象 messageObject.shareObject = shareObject; //调用分享接口 [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) { if (error) { [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"分享失败"]; // 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); [SVProgressHUD showSuccessWithStatus:@"分享成功"]; }else{ // UMSocialLogInfo(@"response data is %@",data); [SVProgressHUD showSuccessWithStatus:@"分享成功"]; } } // [self alertWithError:error]; }]; } -(void)shareImageWithplatformType:(UMSocialPlatformType)platformType withImg:(UIImage *)img{ //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //创建图片内容对象 UMShareImageObject *shareObject = [[UMShareImageObject alloc] init]; //如果有缩略图,则设置缩略图 // shareObject.thumbImage = [UIImage imageNamed:@"share_appicon"]; [shareObject setShareImage:img]; //分享消息对象设置分享内容对象 messageObject.shareObject = shareObject; [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) { if (error) { [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"分享失败"]; }else{ [SVProgressHUD showSuccessWithStatus:@"分享成功"]; } }]; } @end