JXShareManager.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // JXShareManager.m
  3. // shiku_im
  4. //
  5. // Created by MacZ on 16/8/19.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXShareManager.h"
  9. #import "JXMyTools.h"
  10. //#import "WeiboSDK.h"
  11. #import <Social/Social.h>
  12. @implementation JXShareManager
  13. static JXShareManager *shared;
  14. + (JXShareManager *)defaultManager{
  15. static dispatch_once_t onceToken;
  16. dispatch_once(&onceToken, ^{
  17. shared = [[JXShareManager alloc] init];
  18. });
  19. return shared;
  20. }
  21. - (void)shareSuccess{
  22. if ([self.delegate respondsToSelector:@selector(didShareSuccess)]) {
  23. [self.delegate didShareSuccess];
  24. }
  25. [JXMyTools showTipView:Localized(@"ShareSuccess")];
  26. NSLog(@"分享成功");
  27. }
  28. - (void)shareWith:(JXShareModel *)shareModel delegate:(id)delegate{
  29. self.delegate = delegate;
  30. switch (shareModel.shareTo) {
  31. // case JXShareToSina: //微博
  32. // {
  33. //
  34. // if (![WeiboSDK isWeiboAppInstalled]) {
  35. // [g_App showAlert:Localized(@"SinaWBNotInstalled")];
  36. // return;
  37. // }
  38. //
  39. // // [[UMSocialData defaultData].extConfig.sinaData.urlResource setResourceType:UMSocialUrlResourceTypeWeb url:_webUrlString];
  40. // [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:[NSString stringWithFormat:@"%@ %@",shareModel.shareTitle,shareModel.shareUrl] image:nil location:nil urlResource:nil presentedController:self.delegate completion:^(UMSocialResponseEntity *response) {
  41. // if (response.responseCode == UMSResponseCodeSuccess) {
  42. // [self shareSuccess];
  43. // }
  44. // }];
  45. // }
  46. // break;
  47. case JXShareToWechatSesion: //微信
  48. {
  49. [UMSocialData defaultData].extConfig.wechatSessionData.url = shareModel.shareUrl;
  50. [UMSocialData defaultData].extConfig.wechatSessionData.title = shareModel.shareTitle;
  51. [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatSession] content:shareModel.shareContent image:shareModel.shareImage location:nil urlResource:nil presentedController:self.delegate completion:^(UMSocialResponseEntity *response) {
  52. if (response.responseCode == UMSResponseCodeSuccess) {
  53. [self shareSuccess];
  54. }
  55. }];
  56. }
  57. break;
  58. case JXShareToWechatTimeline: //朋友圈
  59. {
  60. [UMSocialData defaultData].extConfig.wechatTimelineData.url = shareModel.shareUrl;
  61. [UMSocialData defaultData].extConfig.wechatTimelineData.title = shareModel.shareTitle;
  62. [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatTimeline] content:shareModel.shareContent image:shareModel.shareImage location:nil urlResource:nil presentedController:self.delegate completion:^(UMSocialResponseEntity *response) {
  63. if (response.responseCode == UMSResponseCodeSuccess) {
  64. [self shareSuccess];
  65. }
  66. }];
  67. }
  68. break;
  69. // case JXShareToFaceBook: //FaceBook
  70. // {
  71. // [[UMSocialControllerService defaultControllerService] setShareText:[NSString stringWithFormat:@"%@ %@",_shareTitle,_webUrlString] shareImage:nil socialUIDelegate:self];
  72. // UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToFacebook];
  73. // snsPlatform.snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
  74. //facebook友盟SDK底层分享接口
  75. // [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToFacebook] content:[NSString stringWithFormat:@"%@",_shareTitle] image:nil location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response) {
  76. // if (response.responseCode == UMSResponseCodeSuccess) {
  77. // [self updateShareActivi];
  78. // NSLog(@"分享成功");
  79. // }
  80. // }];
  81. // self.view.alpha = 0;
  82. //facebook官方SDK分享
  83. // if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
  84. // [g_App showAlert:Localized(@"Facebook NO")];
  85. // return;
  86. // }
  87. //
  88. // FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
  89. //
  90. //
  91. // //链接
  92. // content.contentURL = [NSURL URLWithString:shareModel.shareUrl];
  93. //
  94. // //标题
  95. // content.contentTitle = shareModel.shareTitle;
  96. // //内容
  97. // content.contentDescription = shareModel.shareContent;
  98. // //图片
  99. // content.imageURL = [NSURL URLWithString:shareModel.shareImageUrl];
  100. // //contentURL和imageURL效果不并存,若同时有值,则分享的图片和链接是contentURL
  101. //
  102. //
  103. // FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
  104. // dialog.shareContent = content;
  105. // dialog.mode = FBSDKShareDialogModeNative;
  106. // dialog.fromViewController = self.delegate;
  107. //
  108. // if ([dialog canShow]) {
  109. // [dialog show];
  110. // }
  111. // }
  112. // break;
  113. // case JXShareToTwitter:
  114. // {
  115. // //Twitter(直接分享打开对应的应用,因友盟不支持打开twitter和FaceBook,故此处用非直接分享,使用友盟自定义分享界面样式)
  116. //// [[UMSocialControllerService defaultControllerService] setShareText:[NSString stringWithFormat:@"%@\r\n%@",shareModel.shareContent,shareModel.shareUrl] shareImage:shareModel.shareImage socialUIDelegate:self];
  117. //// UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToTwitter];
  118. //// snsPlatform.snsClickHandler(self.delegate,[UMSocialControllerService defaultControllerService],YES);
  119. // //iOS 自带分享
  120. // SLComposeViewController *shareVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
  121. // //判断是否安装推特
  122. // if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
  123. // [g_App showAlert:Localized(@"TW NO")];
  124. // return;
  125. // }
  126. //
  127. // [shareVC setInitialText:shareModel.shareContent];
  128. // [shareVC addImage:shareModel.shareImage];
  129. // [shareVC addURL:[NSURL URLWithString:shareModel.shareUrl]];
  130. // __block SLComposeViewController *slcVCBlock = shareVC;
  131. // shareVC.completionHandler = ^(SLComposeViewControllerResult result){
  132. // if (result == SLComposeViewControllerResultDone) {
  133. // [self shareSuccess];
  134. // }
  135. // [slcVCBlock dismissViewControllerAnimated:YES completion:nil];
  136. // };
  137. //
  138. // [self.delegate presentViewController:shareVC animated:YES completion:nil];
  139. // }
  140. // break;
  141. // case JXShareToWhatsapp://WhatsApp(只能分享纯文字或纯图片信息);此分享无法触发回调,安卓亦如此。?
  142. // {
  143. //
  144. // [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWhatsapp] content:[NSString stringWithFormat:@"【%@】%@\r\n%@",Localized(@"PinBa"),shareModel.shareTitle,shareModel.shareUrl] image:nil location:nil urlResource:nil presentedController:self.delegate completion:^(UMSocialResponseEntity *response) {
  145. // if (response.responseCode == UMSResponseCodeSuccess) {
  146. // [self shareSuccess];
  147. // }
  148. // }];
  149. //
  150. // }
  151. // break;
  152. // case JXShareToSMS://SMS
  153. // {
  154. // NSString *smsContent = [NSString stringWithFormat:@"%@%@",shareModel.shareTitle,shareModel.shareUrl];
  155. // [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSms] content:smsContent image:nil location:nil urlResource:nil presentedController:self.delegate completion:^(UMSocialResponseEntity *response) {
  156. // if (response.responseCode == UMSResponseCodeSuccess) {
  157. // [self shareSuccess];
  158. // }
  159. // }];
  160. // }
  161. // break;
  162. //
  163. // case JXShareToLine://Line
  164. // {
  165. // NSString *smsContent = [NSString stringWithFormat:@"%@%@",shareModel.shareTitle,shareModel.shareUrl];
  166. // [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToLine] content:smsContent image:nil location:nil urlResource:nil presentedController:self.delegate completion:^(UMSocialResponseEntity *response) {
  167. // if (response.responseCode == UMSResponseCodeSuccess) {
  168. // [self shareSuccess];
  169. // }
  170. // }];
  171. // }
  172. // break;
  173. default:
  174. break;
  175. }
  176. }
  177. //友盟非直接分享回调
  178. #pragma mark UMSocialUIDelegate
  179. - (void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response{
  180. if (response.responseCode == UMSResponseCodeSuccess) {
  181. [self shareSuccess];
  182. }
  183. }
  184. //FaceBook官方SDK分享回调
  185. #pragma mark FBSDKSharingDelegate
  186. //- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results{
  187. // if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 9.0) { //iOS8分享成功results为空;iOS9网页分享成功results不为空,点完成(不分享)results为空
  188. // if (results.count <= 0) {
  189. // return;
  190. // }
  191. // }
  192. //
  193. // [self shareSuccess];
  194. //}
  195. //- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{
  196. // NSLog(@"FB Share error:%@",error);
  197. //}
  198. //
  199. //- (void)sharerDidCancel:(id<FBSDKSharing>)sharer{
  200. // NSLog(@"FB Share cancel");
  201. //}
  202. @end