口袋优选

JZUMShareManager.m 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // JZUMShareManager.m
  3. // JIZHANG
  4. //
  5. // Created by jikaipeng on 2017/10/23.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "JZUMShareManager.h"
  9. #import <UShareUI/UShareUI.h>
  10. @implementation JZUMShareManager
  11. + (instancetype)shareInstance{
  12. static JZUMShareManager *shareManger = nil;
  13. static dispatch_once_t onceToken;
  14. dispatch_once(&onceToken, ^{
  15. if (shareManger == nil) {
  16. shareManger = [[JZUMShareManager 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 */
  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. // 根据获取的platformType确定所选平台进行下一步操作
  43. [self shareWebPagewithplatformType:platformType title:@"钱多多随手记" desc:@"钱多多记账,最简洁的随手记账软件,官方推荐,百万财务用户的记账首选APP" thumImage:@"mine_about_icon" webpageUrl:shareUrl];
  44. }];
  45. }
  46. - (void)alertWithError:(NSError *)error
  47. {
  48. NSString *result = nil;
  49. if (!error) {
  50. // result = [NSString stringWithFormat:@"分享成功"];
  51. [SVProgressHUD showSuccessWithStatus:@"分享成功"];
  52. }
  53. else{
  54. NSMutableString *str = [NSMutableString string];
  55. if (error.userInfo) {
  56. for (NSString *key in error.userInfo) {
  57. [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]];
  58. }
  59. }
  60. if (error) {
  61. result = [NSString stringWithFormat:@"Share fail with error code: %d\n%@",(int)error.code, str];
  62. // [MBProgressHUD showError:result];
  63. }
  64. else{
  65. // result = [NSString stringWithFormat:@"Share fail"];
  66. [SVProgressHUD dismiss];
  67. [MBProgressHUD showMessage:@"分享失败"];
  68. }
  69. }
  70. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
  71. message:result
  72. delegate:nil
  73. cancelButtonTitle:NSLocalizedString(@"sure", @"确定")
  74. otherButtonTitles:nil];
  75. [alert show];
  76. }
  77. - (void)configUSharePlatforms{
  78. /*
  79. 设置微信的appKey和appSecret
  80. [微信平台从U-Share 4/5升级说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1
  81. */
  82. [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WX_APPID appSecret:WX_APP_SECRET redirectURL:nil];
  83. /* 设置分享到QQ互联的appID
  84. * U-Share SDK为了兼容大部分平台命名,统一用appKey和appSecret进行参数设置,而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
  85. 100424468.no permission of union id
  86. [QQ/QZone平台集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_3
  87. */
  88. /*
  89. * 移除相应平台的分享,如微信收藏
  90. */
  91. [[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite),@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Tim)]];
  92. }
  93. - (void)confitUShareSettings{
  94. /*
  95. * 打开图片水印
  96. */
  97. //[UMSocialGlobal shareInstance].isUsingWaterMark = YES;
  98. /*
  99. * 关闭强制验证https,可允许http图片分享,但需要在info.plist设置安全域名
  100. <key>NSAppTransportSecurity</key>
  101. <dict>
  102. <key>NSAllowsArbitraryLoads</key>
  103. <true/>
  104. </dict>
  105. */
  106. //[UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;
  107. }
  108. - (void)shareText:(NSString *)text{
  109. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  110. messageObject.text = text;
  111. [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  112. NSString *message = nil;
  113. if (!error) {
  114. message = [NSString stringWithFormat:@"分享成功"];
  115. } else {
  116. message = [NSString stringWithFormat:@"失败原因Code: %d\n",(int)error.code];
  117. }
  118. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
  119. message:message
  120. delegate:nil
  121. cancelButtonTitle:NSLocalizedString(@"确定", nil)
  122. otherButtonTitles:nil];
  123. [alert show];
  124. }];
  125. }
  126. - (void)shareWebPagewithplatformType:(UMSocialPlatformType)platformType title:(NSString *)title desc:(NSString *)desc thumImage:(NSString *)imageName webpageUrl:(NSString *)webUrl{
  127. //创建分享消息对象
  128. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  129. //创建网页内容对象
  130. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:[UIImage imageNamed:imageName]];
  131. //设置网页地址
  132. shareObject.webpageUrl = webUrl;
  133. //分享消息对象设置分享内容对象
  134. messageObject.shareObject = shareObject;
  135. //调用分享接口
  136. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
  137. if (error) {
  138. [SVProgressHUD dismiss];
  139. [MBProgressHUD showMessage:@"分享失败"];
  140. // UMSocialLogInfo(@"************Share fail with error %@*********",error);
  141. }else{
  142. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  143. UMSocialShareResponse *resp = data;
  144. // //分享结果消息
  145. // UMSocialLogInfo(@"response message is %@",resp.message);
  146. // //第三方原始返回的数据
  147. // UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
  148. [SVProgressHUD showSuccessWithStatus:@"分享成功"];
  149. }else{
  150. // UMSocialLogInfo(@"response data is %@",data);
  151. [SVProgressHUD showSuccessWithStatus:@"分享成功"];
  152. }
  153. }
  154. // [self alertWithError:error];
  155. }];
  156. }
  157. @end