JXShareMonyVc.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. //
  2. // JXShareMonyVc.m
  3. // shiku_im
  4. //
  5. // Created by os on 2020/7/3.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXShareMonyVc.h"
  9. #import "UMSocialSnsService.h"
  10. #import "UMSocialSnsPlatformManager.h"
  11. #import "MyButton.h"
  12. @interface JXShareMonyVc ()
  13. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewHHH;
  14. @property (weak, nonatomic) IBOutlet UIImageView *codeIMG;
  15. @property (weak, nonatomic) IBOutlet UIButton *jixinNoBtn;
  16. @property (weak, nonatomic) IBOutlet UIImageView *shareIMG;
  17. @end
  18. @implementation JXShareMonyVc
  19. - (void)click{
  20. [g_navigation dismissViewController:self animated:YES];
  21. }
  22. - (void)defineNavBar:(NSString *)title andRinghtBtnImg:(NSString *)image
  23. {
  24. UIView *navView = [[UIView alloc] init];
  25. [self.view addSubview:navView];
  26. navView.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_TOP);
  27. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  28. backBtn.frame = CGRectMake(0,JX_SCREEN_HEIGHT>812?44:20,44, 44);
  29. [backBtn setImage:[UIImage imageNamed:@"photo_title_back_black"] forState:0];
  30. backBtn.tag = 1001;
  31. [backBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
  32. [navView addSubview:backBtn];
  33. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,(JX_SCREEN_HEIGHT>812?44:20), JX_SCREEN_WIDTH-100, 44)];
  34. label.text = title;
  35. label.textColor = kRGBColor51;
  36. label.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
  37. label.textAlignment = NSTextAlignmentCenter;
  38. [navView addSubview:label];
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. _shareIMG.userInteractionEnabled=YES;
  43. self.topViewHHH.constant=JX_SCREEN_HEIGHT>=812?24:0;
  44. [self defineNavBar:@"分享赚钱" andRinghtBtnImg:@"1"];
  45. NSArray *imageS=@[@"circle_of_friends_icon",@"微信",@"qq好友",@"保存图片"];
  46. NSArray *titleS=@[@"微信朋友圈",@"微信好友",@"QQ好友",@"保存图片"];
  47. for (int i=0; i<4; i++) {
  48. MyButton *bottomBtn = [[MyButton alloc]init];
  49. //bottomBtn.backgroundColor=kRGBColor246;
  50. bottomBtn.tag=i;
  51. //[bottomBtn setTitleColor:kRGBColor(222, 29, 19) forState:UIControlStateNormal];
  52. [bottomBtn setImage:[UIImage imageNamed:imageS[i]] forState:UIControlStateNormal];
  53. [bottomBtn setTitle:titleS[i] forState:UIControlStateNormal];
  54. [_shareIMG addSubview:bottomBtn];
  55. [bottomBtn addTarget:self action:@selector(saveBttIMG1:) forControlEvents:UIControlEventTouchUpInside];
  56. //bottomBtn.frame=CGRectMake(i*((JX_SCREEN_WIDTH-60)/4), 0, (JX_SCREEN_WIDTH-60)/4, 60);
  57. [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(i*((JX_SCREEN_WIDTH-60)/4));
  59. make.width.mas_equalTo((JX_SCREEN_WIDTH-60)/4);
  60. // make.height.mas_equalTo(60);
  61. make.top.mas_equalTo(0);
  62. }];
  63. }
  64. [SVProgressHUD show];
  65. [g_server getAppResource:@"6" ToView:self];
  66. long time = (long)[[NSDate date] timeIntervalSince1970];
  67. time = (time *1000 + g_server.timeDifference);
  68. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  69. [g_server getact_getinviteget:salt andUserId:g_server.myself.userId andToView:self];
  70. }
  71. #pragma mark --- 请求成功
  72. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  73. [SVProgressHUD dismiss];
  74. //NSLog(@"dict: %@ --- arry: %@",dict ,array1 );
  75. if([aDownload.action isEqualToString:act_getAppResource]){
  76. NSDictionary *dict=[array1 firstObject];
  77. NSString *string=dict[@"link"];
  78. //创建过滤器
  79. CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
  80. //过滤器恢复默认
  81. [filter setDefaults];
  82. //给过滤器添加数据<字符串长度893>
  83. NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  84. [filter setValue:data forKey:@"inputMessage"];
  85. //获取二维码过滤器生成二维码
  86. CIImage *image = [filter outputImage];
  87. UIImage *img = [self createNonInterpolatedUIImageFromCIImage:image WithSize:140];
  88. self.codeIMG.image=img;
  89. }
  90. else if([aDownload.action isEqualToString:act_getinviteget])
  91. {
  92. NSDictionary *dictM=dict;
  93. NSString *str=[NSString stringWithFormat:@"邀请码:%@",dictM[@"invite"]];
  94. [self.jixinNoBtn setTitle:str forState:UIControlStateNormal];
  95. }
  96. }
  97. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  98. [SVProgressHUD dismiss];
  99. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  100. if([errorCode isEqualToString:@"权限验证失败"])
  101. {
  102. if ([aDownload.action isEqualToString:act_GetBalanceRedTimes])
  103. {
  104. }else{
  105. }
  106. }
  107. return [errorCode intValue];
  108. }
  109. //分享
  110. - (void)saveBttIMG1:(UIButton *)sender{
  111. if (sender.tag==0) {
  112. [self shareAction:
  113. @[UMShareToWechatTimeline] pathUrl:@"https://apps.apple.com/cn/app/%E8%81%8A%E5%95%B5-%E4%B8%8E%E6%9C%8B%E5%8F%8B%E4%B8%80%E8%B5%B7%E7%95%85%E8%81%8A/id1463401862" ];
  114. } if (sender.tag==1) {
  115. [self shareAction:
  116. @[UMShareToWechatSession] pathUrl:@"https://apps.apple.com/cn/app/%E8%81%8A%E5%95%B5-%E4%B8%8E%E6%9C%8B%E5%8F%8B%E4%B8%80%E8%B5%B7%E7%95%85%E8%81%8A/id1463401862" ];
  117. } if (sender.tag==2) {
  118. NSString *musicPath1=@"https://apps.apple.com/cn/app/%E8%81%8A%E5%95%B5-%E4%B8%8E%E6%9C%8B%E5%8F%8B%E4%B8%80%E8%B5%B7%E7%95%85%E8%81%8A/id1463401862";
  119. NSString *yaoqingM =self.jixinNoBtn.titleLabel.text;
  120. NSString *dicript = [NSString stringWithFormat:@"您的邀请码是:%@%@",yaoqingM,@" 即信—安全稳定的赚钱平台 \n给你推荐一款可以赚钱的APP。我今天又收入了999元,现在还有3个名额,快进来下载一起赚钱吧!"];
  121. UIImage *shareImage = [UIImage imageNamed:@"ALOGO_120"];
  122. NSURL *url = [NSURL fileURLWithPath:musicPath1];
  123. NSArray * activityItems = @[dicript,shareImage,url];
  124. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
  125. //去除一些不需要的图标选项
  126. activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypePostToWeibo, UIActivityTypePostToTencentWeibo];
  127. //成功失败的回调block
  128. UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) {
  129. if (completed){
  130. }else{
  131. }
  132. };
  133. activityVC.completionWithItemsHandler = myBlock;
  134. [self presentViewController:activityVC animated:YES completion:nil];
  135. }
  136. if (sender.tag==3) {
  137. UIImage *saveIMG = [self captureImageFromView:self.view];
  138. UIImageWriteToSavedPhotosAlbum(saveIMG, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  139. }
  140. }
  141. - (void)saveBttIMG:(UIButton *)showBt{
  142. UIImage *saveIMG = [self captureImageFromView:self.view];
  143. UIImageWriteToSavedPhotosAlbum(saveIMG, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  144. }
  145. -(UIImage *)captureImageFromView:(UIView *)view{
  146. UIGraphicsBeginImageContextWithOptions(self.view.frame.size,NO, 0);
  147. [[UIColor clearColor] setFill];
  148. [[UIBezierPath bezierPathWithRect:self.view.bounds] fill];
  149. CGContextRef ctx = UIGraphicsGetCurrentContext();
  150. [self.view.layer renderInContext:ctx];
  151. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  152. UIGraphicsEndImageContext();
  153. return image;
  154. }
  155. //下面得到分享完成的回调
  156. -(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
  157. {
  158. NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response);
  159. //根据`responseCode`得到发送结果,如果分享成功
  160. if(response.responseCode == UMSResponseCodeSuccess)
  161. {
  162. //得到分享到的微博平台名
  163. NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
  164. }
  165. }
  166. - (void)shareAction:(NSArray *)type pathUrl:(NSString *)musicPath {
  167. //[self shareAction: @[ UMShareToQzone,UMShareToQQ,UMShareToTencent] pathUrl: ];
  168. musicPath=@"https://apps.apple.com/cn/app/%E8%81%8A%E5%95%B5-%E4%B8%8E%E6%9C%8B%E5%8F%8B%E4%B8%80%E8%B5%B7%E7%95%85%E8%81%8A/id1463401862";
  169. NSString *yaoqingM =self.jixinNoBtn.titleLabel.text;
  170. NSString *dicript = [NSString stringWithFormat:@"您的邀请码是:%@%@",yaoqingM,@" 即信—安全稳定的赚钱平台 \n给你推荐一款可以赚钱的APP。我今天又收入了999元,现在还有3个名额,快进来下载一起赚钱吧!"];
  171. UIImage *shareImage = [UIImage imageNamed:@"ALOGO_120"];
  172. NSURL *url = [NSURL fileURLWithPath:musicPath];
  173. NSArray * activityItems = @[dicript,musicPath];
  174. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
  175. //去除一些不需要的图标选项
  176. activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypePostToWeibo, UIActivityTypePostToTencentWeibo];
  177. //成功失败的回调block
  178. UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) {
  179. if (completed){
  180. }else{
  181. }
  182. };
  183. activityVC.completionWithItemsHandler = myBlock;
  184. [self presentViewController:activityVC animated:YES completion:nil];
  185. return;
  186. NSString *shareText = dicript; //分享内嵌文字
  187. [UMSocialSnsService presentSnsIconSheetView:self appKey:@"5edaacbe978eea085d11d331" shareText:shareText shareImage:shareImage shareToSnsNames:type delegate:self];
  188. return;
  189. }
  190. - (UIImage *)createNonInterpolatedUIImageFromCIImage:(CIImage *)image WithSize:(CGFloat)size
  191. {
  192. CGRect extent = CGRectIntegral(image.extent);
  193. CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
  194. //创建bitmap
  195. size_t width = CGRectGetWidth(extent)*scale;
  196. size_t height = CGRectGetHeight(extent)*scale;
  197. CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
  198. CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
  199. CIContext *context = [CIContext contextWithOptions:nil];
  200. CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
  201. CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
  202. CGContextScaleCTM(bitmapRef, scale, scale);
  203. CGContextDrawImage(bitmapRef, extent, bitmapImage);
  204. //保存图片
  205. CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
  206. CGContextRelease(bitmapRef);
  207. CGImageRelease(bitmapImage);
  208. return [UIImage imageWithCGImage:scaledImage];
  209. }
  210. #pragma mark -- <保存到相册>
  211. -(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
  212. NSString *msg = nil ;
  213. if(error){
  214. msg = @"保存图片失败" ;
  215. }else{
  216. msg = @"保存图片成功" ;
  217. }
  218. }
  219. /*
  220. #pragma mark - Navigation
  221. // In a storyboard-based application, you will often want to do a little preparation before navigation
  222. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  223. // Get the new view controller using [segue destinationViewController].
  224. // Pass the selected object to the new view controller.
  225. }
  226. */
  227. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  228. [self.view endEditing:YES];
  229. }
  230. @end