JXShareMonyVc.m 11 KB

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