猎豆优选

WechatShareTool.m 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // WechatShareTool.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/9/26.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "WechatShareTool.h"
  9. @implementation WechatShareTool
  10. + (void)shareImageWithplatformType:(UMSocialPlatformType)platformType withDict:(NSDictionary *)dict {
  11. //创建分享消息对象
  12. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  13. //创建图片内容对象
  14. UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
  15. [shareObject setShareImage:[dict objectForKey:@"shareImageUrl"]];
  16. //分享消息对象设置分享内容对象
  17. messageObject.shareObject = shareObject;
  18. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
  19. }];
  20. }
  21. + (void)shareURLWithplatformType:(UMSocialPlatformType)platformType withDict:(NSDictionary *)dict {
  22. //创建分享消息对象
  23. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  24. //创建图片内容对象
  25. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:dict[@"shareTitle"] descr:dict[@"shareDescirpt"] thumImage:dict[@"shareImageUrl"]];
  26. shareObject.webpageUrl = dict[@"shareUrl"];
  27. messageObject.shareObject = shareObject;
  28. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
  29. }];
  30. }
  31. + (void)shareVideoWithplatformType:(UMSocialPlatformType)platformType withDict:(NSDictionary *)dict {
  32. //创建分享消息对象
  33. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  34. //创建视频内容对象
  35. UMShareVideoObject *shareObject = [UMShareVideoObject shareObjectWithTitle:dict[@"shareTitle"] descr:dict[@"shareDescription"] thumImage:dict[@"shareThumb"]];
  36. //设置视频网页播放地址
  37. shareObject.videoUrl = dict[@"shareVideoUrl"];
  38. // shareObject.videoStreamUrl = @"这里设置视频数据流地址(如果有的话,而且也要看所分享的平台支不支持)";
  39. //分享消息对象设置分享内容对象
  40. messageObject.shareObject = shareObject;
  41. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
  42. }];
  43. }
  44. + (void)shareMinProgramWithplatformType:(UMSocialPlatformType)platformType withDict:(NSDictionary *)dict {
  45. //创建分享消息对象
  46. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  47. UMShareMiniProgramObject *shareObject = [UMShareMiniProgramObject shareObjectWithTitle:dict[@"shareTitle"] descr:dict[@"shareDescription"] thumImage:dict[@"shareThumb"]];
  48. shareObject.webpageUrl = dict[@"shareUrl"];
  49. shareObject.userName = dict[@"shareID"];
  50. shareObject.path = dict[@"sharePath"];
  51. messageObject.shareObject = shareObject;
  52. // shareObject.hdImageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logo" ofType:@"png"]];
  53. NSString *minType = dict[@"minType"];
  54. switch (minType.integerValue) {
  55. case 1:
  56. shareObject.miniProgramType = UShareWXMiniProgramTypeRelease; //正式版
  57. break;
  58. case 2:
  59. shareObject.miniProgramType = UShareWXMiniProgramTypeTest; // 开发版
  60. break;
  61. case 3:
  62. shareObject.miniProgramType = UShareWXMiniProgramTypePreview; //体验版
  63. break;
  64. default:
  65. shareObject.miniProgramType = UShareWXMiniProgramTypeRelease; // //线上
  66. break;
  67. }
  68. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
  69. }];
  70. }
  71. @end