口袋优选

shareView.m 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // shareView.m
  3. // KXYiMa
  4. //
  5. // Created by jcymac on 2018/1/24.
  6. // Copyright © 2018年 jcymac. All rights reserved.
  7. //
  8. #import "shareView.h"
  9. #import "HYUMShareManager.h"
  10. #import "WXApi.h"
  11. @interface shareView()
  12. @property(nonatomic,strong)NSString *title;
  13. @property(nonatomic,strong)NSString *desc;
  14. @property(nonatomic,strong)NSString *imageUrl;
  15. @property(nonatomic,strong)NSString *webUrl;
  16. @property(nonatomic,strong)UIImage *img;
  17. @end
  18. @implementation shareView
  19. -(void)awakeFromNib{
  20. [super awakeFromNib];
  21. [self.shareButtonOne addTarget:self action:@selector(shareOneAction) forControlEvents:UIControlEventTouchUpInside];
  22. [self.shareButtonTwo addTarget:self action:@selector(shareTwoAction) forControlEvents:UIControlEventTouchUpInside];
  23. }
  24. //分享到微信
  25. -(void)shareOneAction{
  26. NSLog(@"shareOneAction");
  27. if (![WXApi isWXAppInstalled]) {
  28. [MBProgressHUD showMessage:@"没有安装微信客户端"];
  29. if (self.shareButtonOneBlock) {
  30. self.shareButtonOneBlock();
  31. }
  32. return;
  33. }
  34. if (self.shareType==ShareTypeUrl) {
  35. [[HYUMShareManager shareInstance] shareWebPagewithplatformType:UMSocialPlatformType_WechatSession title:self.title desc:self.desc thumImageUrl:self.imageUrl webpageUrl:self.webUrl];
  36. }else if(self.shareType==ShareTypeImage){
  37. if (self.imgUrl.length > 0) {
  38. [MobClick event:InvateImageWeiXin label:self.imgUrl];
  39. }
  40. [[HYUMShareManager shareInstance] shareImageWithplatformType:UMSocialPlatformType_WechatSession withImg:self.img];
  41. }
  42. if (self.shareButtonOneBlock) {
  43. self.shareButtonOneBlock();
  44. }
  45. }
  46. //分享到朋友圈
  47. -(void)shareTwoAction{
  48. NSLog(@"shareTwoAction");
  49. if (![WXApi isWXAppInstalled]) {
  50. [MBProgressHUD showMessage:@"没有安装微信客户端"];
  51. if (self.shareButtonTwoBlock) {
  52. self.shareButtonTwoBlock();
  53. }
  54. return;
  55. }
  56. if (self.shareType==ShareTypeUrl) {
  57. [[HYUMShareManager shareInstance] shareWebPagewithplatformType:UMSocialPlatformType_WechatTimeLine title:self.title desc:self.desc thumImageUrl:self.imageUrl webpageUrl:self.webUrl];
  58. }else if(self.shareType==ShareTypeImage){
  59. if (self.imgUrl.length > 0) {
  60. [MobClick event:InvateImageWeiXinCircle label:self.imgUrl];
  61. }
  62. [[HYUMShareManager shareInstance] shareImageWithplatformType:UMSocialPlatformType_WechatTimeLine withImg:self.img];
  63. }
  64. if (self.shareButtonTwoBlock) {
  65. self.shareButtonTwoBlock();
  66. }
  67. }
  68. -(void)shareWeChatTitle:(NSString *)title desc:(NSString *)desc imageUrl:(NSString *)imageUrl webUrl:(NSString *)webUrl{
  69. self.shareType=ShareTypeUrl;
  70. _title=title;
  71. _desc=desc;
  72. _imageUrl=imageUrl;
  73. _webUrl=webUrl;
  74. }
  75. -(void)shareImage:(UIImage *)img{
  76. self.shareType=ShareTypeImage;
  77. _img=img;
  78. }
  79. @end