两折买改口袋样式

HYUMShareManager.m 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // HYUMShareManager.m
  3. // JIZHANG
  4. //
  5. // Created by jikaipeng on 2017/10/23.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "HYUMShareManager.h"
  9. #import <UShareUI/UShareUI.h>
  10. @implementation HYUMShareManager
  11. + (instancetype)shareInstance{
  12. static HYUMShareManager *shareManger = nil;
  13. static dispatch_once_t onceToken;
  14. dispatch_once(&onceToken, ^{
  15. if (shareManger == nil) {
  16. shareManger = [[HYUMShareManager alloc]init];
  17. }
  18. });
  19. return shareManger;
  20. }
  21. - (void)setUMShare{
  22. /* 打开日志 */
  23. [[UMSocialManager defaultManager] openLog:NO];
  24. // 打开图片水印
  25. //[UMSocialGlobal shareInstance].isUsingWaterMark = YES;
  26. [UMSocialGlobal shareInstance].isClearCacheWhenGetUserInfo = NO;
  27. /* 设置友盟appkey setUmSocialAppkey */
  28. [[UMSocialManager defaultManager] setUmSocialAppkey:UMAPP_KEY];
  29. [self configUSharePlatforms];
  30. [self confitUShareSettings];
  31. }
  32. - (void)shareWithUI{
  33. [UMSocialShareUIConfig shareInstance].shareTitleViewConfig.isShow = NO;
  34. [UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom;
  35. [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxRowCountForPortraitAndBottom = 2;
  36. [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxColumnCountForPortraitAndBottom = 2;
  37. // [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxRowCountForLandscapeAndMid = 2;
  38. // [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxColumnCountForLandscapeAndMid = 6;
  39. //显示分享面板
  40. [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
  41. NSString *shareUrl =@"http://www.baidu.com";
  42. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  43. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  44. // 根据获取的platformType确定所选平台进行下一步操作
  45. [self shareWebPagewithplatformType:platformType title:app_Name desc:@"专业备孕、怀孕、育儿助手工具,百万怀孕妈妈的选择!" thumImageUrl:@"" webpageUrl:shareUrl];
  46. }];
  47. }
  48. - (void)alertWithError:(NSError *)error
  49. {
  50. NSString *result = nil;
  51. if (!error) {
  52. // result = [NSString stringWithFormat:@"分享成功"];
  53. [SVProgressHUD showSuccessWithStatus:@"分享成功!"];
  54. }
  55. else{
  56. NSMutableString *str = [NSMutableString string];
  57. if (error.userInfo) {
  58. for (NSString *key in error.userInfo) {
  59. [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]];
  60. }
  61. }
  62. if (error) {
  63. result = [NSString stringWithFormat:@"Share fail with error code: %d\n%@",(int)error.code, str];
  64. // [MBProgressHUD showError:result];
  65. }
  66. else{
  67. // result = [NSString stringWithFormat:@"Share fail"];
  68. [SVProgressHUD dismiss];
  69. [MBProgressHUD showMessage:@"分享失败"];
  70. }
  71. }
  72. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
  73. message:result
  74. delegate:nil
  75. cancelButtonTitle:NSLocalizedString(@"sure", @"确定")
  76. otherButtonTitles:nil];
  77. [alert show];
  78. }
  79. - (void)configUSharePlatforms{
  80. /*
  81. 设置微信的appKey和appSecret
  82. [微信平台从U-Share 4/5升级说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1
  83. */
  84. [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WX_APPID appSecret:WX_APP_SECRET redirectURL:nil];
  85. /* 设置分享到QQ互联的appID
  86. * U-Share SDK为了兼容大部分平台命名,统一用appKey和appSecret进行参数设置,而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
  87. 100424468.no permission of union id
  88. [QQ/QZone平台集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_3
  89. */
  90. // [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:QQ_APPKEY/*设置QQ平台的appID*/ appSecret:nil redirectURL:nil];
  91. /*
  92. * 移除相应平台的分享,如微信收藏
  93. */
  94. [[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite),@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Tim)]];
  95. }
  96. - (void)confitUShareSettings{
  97. /*
  98. * 打开图片水印
  99. */
  100. //[UMSocialGlobal shareInstance].isUsingWaterMark = YES;
  101. /*
  102. * 关闭强制验证https,可允许http图片分享,但需要在info.plist设置安全域名
  103. <key>NSAppTransportSecurity</key>
  104. <dict>
  105. <key>NSAllowsArbitraryLoads</key>
  106. <true/>
  107. </dict>
  108. */
  109. //[UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;
  110. }
  111. - (void)shareText:(NSString *)text{
  112. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  113. messageObject.text = text;
  114. [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  115. NSString *message = nil;
  116. if (!error) {
  117. message = [NSString stringWithFormat:@"分享成功"];
  118. } else {
  119. message = [NSString stringWithFormat:@"失败原因Code: %d\n",(int)error.code];
  120. }
  121. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
  122. message:message
  123. delegate:nil
  124. cancelButtonTitle:NSLocalizedString(@"确定", nil)
  125. otherButtonTitles:nil];
  126. [alert show];
  127. }];
  128. }
  129. - (void)shareWebPagewithplatformType:(UMSocialPlatformType)platformType title:(NSString *)title desc:(NSString *)desc thumImageUrl:(NSString *)imageUrl webpageUrl:(NSString *)webUrl{
  130. //创建分享消息对象
  131. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  132. //创建网页内容对象
  133. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]]];
  134. //设置网页地址
  135. shareObject.webpageUrl = webUrl;
  136. //分享消息对象设置分享内容对象
  137. messageObject.shareObject = shareObject;
  138. //调用分享接口
  139. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
  140. if (error) {
  141. [SVProgressHUD dismiss];
  142. [MBProgressHUD showMessage:@"分享失败"];
  143. // UMSocialLogInfo(@"************Share fail with error %@*********",error);
  144. }else{
  145. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  146. UMSocialShareResponse *resp = data;
  147. // //分享结果消息
  148. // UMSocialLogInfo(@"response message is %@",resp.message);
  149. // //第三方原始返回的数据
  150. // UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
  151. [SVProgressHUD showSuccessWithStatus:@"分享成功"];
  152. }else{
  153. // UMSocialLogInfo(@"response data is %@",data);
  154. [SVProgressHUD showSuccessWithStatus:@"分享成功"];
  155. }
  156. }
  157. // [self alertWithError:error];
  158. }];
  159. }
  160. -(void)shareImageWithplatformType:(UMSocialPlatformType)platformType withImg:(UIImage *)img{
  161. //创建分享消息对象
  162. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  163. //创建图片内容对象
  164. UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
  165. //如果有缩略图,则设置缩略图
  166. // shareObject.thumbImage = [UIImage imageNamed:@"share_appicon"];
  167. [shareObject setShareImage:img];
  168. //分享消息对象设置分享内容对象
  169. messageObject.shareObject = shareObject;
  170. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
  171. if (error) {
  172. [SVProgressHUD dismiss];
  173. [MBProgressHUD showMessage:@"分享失败"];
  174. }else{
  175. [SVProgressHUD showSuccessWithStatus:@"分享成功"];
  176. }
  177. }];
  178. }
  179. @end