// // JZUMShareManager.m // JIZHANG // // Created by jikaipeng on 2017/10/23. // Copyright © 2017年 kuxuan. All rights reserved. // #import "JZUMShareManager.h" #import @implementation JZUMShareManager + (instancetype)shareInstance{ static JZUMShareManager *shareManger = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ if (shareManger == nil) { shareManger = [[JZUMShareManager alloc]init]; } }); return shareManger; } - (void)setUMShare{ /* 打开日志 */ [[UMSocialManager defaultManager] openLog:NO]; // 打开图片水印 //[UMSocialGlobal shareInstance].isUsingWaterMark = YES; [UMSocialGlobal shareInstance].isClearCacheWhenGetUserInfo = NO; /* 设置友盟appkey */ [[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"; // 根据获取的platformType确定所选平台进行下一步操作 [self shareWebPagewithplatformType:platformType title:@"钱多多随手记" desc:@"钱多多记账,最简洁的随手记账软件,官方推荐,百万财务用户的记账首选APP" thumImage:@"mine_about_icon" 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] 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 thumImage:(NSString *)imageName webpageUrl:(NSString *)webUrl{ //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //创建网页内容对象 UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:[UIImage imageNamed:imageName]]; //设置网页地址 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]; }]; } @end