// // JXShareMonyVc.m // shiku_im // // Created by os on 2020/7/3. // Copyright © 2020 Reese. All rights reserved. // #import "JXShareMonyVc.h" #import "UMSocialSnsService.h" #import "UMSocialSnsPlatformManager.h" #import "MyButton.h" @interface JXShareMonyVc () @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewHHH; @property (weak, nonatomic) IBOutlet UIImageView *codeIMG; @property (weak, nonatomic) IBOutlet UIButton *jixinNoBtn; @property (weak, nonatomic) IBOutlet UIImageView *shareIMG; @end @implementation JXShareMonyVc - (void)viewDidLoad { [super viewDidLoad]; _shareIMG.userInteractionEnabled=YES; self.topViewHHH.constant=JX_SCREEN_HEIGHT>=812?24:0; NSArray *imageS=@[@"circle_of_friends_icon",@"微信",@"qq好友",@"保存图片"]; NSArray *titleS=@[@"微信朋友圈",@"微信好友",@"QQ好友",@"保存图片"]; for (int i=0; i<4; i++) { MyButton *bottomBtn = [[MyButton alloc]init]; //bottomBtn.backgroundColor=kRGBColor246; bottomBtn.tag=i; //[bottomBtn setTitleColor:kRGBColor(222, 29, 19) forState:UIControlStateNormal]; [bottomBtn setImage:[UIImage imageNamed:imageS[i]] forState:UIControlStateNormal]; [bottomBtn setTitle:titleS[i] forState:UIControlStateNormal]; [_shareIMG addSubview:bottomBtn]; [bottomBtn addTarget:self action:@selector(saveBttIMG1:) forControlEvents:UIControlEventTouchUpInside]; //bottomBtn.frame=CGRectMake(i*((JX_SCREEN_WIDTH-60)/4), 0, (JX_SCREEN_WIDTH-60)/4, 60); [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(i*((JX_SCREEN_WIDTH-60)/4)); make.width.mas_equalTo((JX_SCREEN_WIDTH-60)/4); // make.height.mas_equalTo(60); make.top.mas_equalTo(0); }]; } [SVProgressHUD show]; [g_server getAppResource:@"6" ToView:self]; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server getact_getinviteget:salt andUserId:g_server.myself.userId andToView:self]; } #pragma mark --- 请求成功 -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ [SVProgressHUD dismiss]; //NSLog(@"dict: %@ --- arry: %@",dict ,array1 ); if([aDownload.action isEqualToString:act_getAppResource]){ NSDictionary *dict=[array1 firstObject]; NSString *string=dict[@"link"]; //创建过滤器 CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"]; //过滤器恢复默认 [filter setDefaults]; //给过滤器添加数据<字符串长度893> NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; [filter setValue:data forKey:@"inputMessage"]; //获取二维码过滤器生成二维码 CIImage *image = [filter outputImage]; UIImage *img = [self createNonInterpolatedUIImageFromCIImage:image WithSize:140]; self.codeIMG.image=img; } else if([aDownload.action isEqualToString:act_getinviteget]) { NSDictionary *dictM=dict; NSString *str=[NSString stringWithFormat:@"邀请码:%@",dictM[@"invite"]]; [self.jixinNoBtn setTitle:str forState:UIControlStateNormal]; } } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ [SVProgressHUD dismiss]; NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]; if([errorCode isEqualToString:@"权限验证失败"]) { if ([aDownload.action isEqualToString:act_GetBalanceRedTimes]) { }else{ } } return [errorCode intValue]; } //分享 - (void)saveBttIMG1:(UIButton *)sender{ if (sender.tag==0) { [self shareAction: @[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" ]; } if (sender.tag==1) { [self shareAction: @[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" ]; } if (sender.tag==2) { 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"; NSString *yaoqingM =self.jixinNoBtn.titleLabel.text; NSString *dicript = [NSString stringWithFormat:@"您的邀请码是:%@%@",yaoqingM,@" 即信—安全稳定的赚钱平台 \n给你推荐一款可以赚钱的APP。我今天又收入了999元,现在还有3个名额,快进来下载一起赚钱吧!"]; UIImage *shareImage = [UIImage imageNamed:@"ALOGO_1200"]; NSURL *url = [NSURL fileURLWithPath:musicPath1]; NSArray * activityItems = @[dicript,shareImage,url]; UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil]; //去除一些不需要的图标选项 activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypePostToWeibo, UIActivityTypePostToTencentWeibo]; //成功失败的回调block UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) { if (completed){ }else{ } }; activityVC.completionWithItemsHandler = myBlock; [self presentViewController:activityVC animated:YES completion:nil]; } if (sender.tag==3) { UIImage *saveIMG = [self captureImageFromView:self.view]; UIImageWriteToSavedPhotosAlbum(saveIMG, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } } - (void)saveBttIMG:(UIButton *)showBt{ UIImage *saveIMG = [self captureImageFromView:self.view]; UIImageWriteToSavedPhotosAlbum(saveIMG, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } -(UIImage *)captureImageFromView:(UIView *)view{ UIGraphicsBeginImageContextWithOptions(self.view.frame.size,NO, 0); [[UIColor clearColor] setFill]; [[UIBezierPath bezierPathWithRect:self.view.bounds] fill]; CGContextRef ctx = UIGraphicsGetCurrentContext(); [self.view.layer renderInContext:ctx]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } //下面得到分享完成的回调 -(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response { NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response); //根据`responseCode`得到发送结果,如果分享成功 if(response.responseCode == UMSResponseCodeSuccess) { //得到分享到的微博平台名 NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]); } } - (void)shareAction:(NSArray *)type pathUrl:(NSString *)musicPath { //[self shareAction: @[ UMShareToQzone,UMShareToQQ,UMShareToTencent] pathUrl: ]; 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"; NSString *yaoqingM =self.jixinNoBtn.titleLabel.text; NSString *dicript = [NSString stringWithFormat:@"您的邀请码是:%@%@",yaoqingM,@" 即信—安全稳定的赚钱平台 \n给你推荐一款可以赚钱的APP。我今天又收入了999元,现在还有3个名额,快进来下载一起赚钱吧!"]; UIImage *shareImage = [UIImage imageNamed:@"ALOGO_1200"]; NSURL *url = [NSURL fileURLWithPath:musicPath]; NSArray * activityItems = @[dicript,musicPath]; UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil]; //去除一些不需要的图标选项 activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypePostToWeibo, UIActivityTypePostToTencentWeibo]; //成功失败的回调block UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) { if (completed){ }else{ } }; activityVC.completionWithItemsHandler = myBlock; [self presentViewController:activityVC animated:YES completion:nil]; return; NSString *shareText = dicript; //分享内嵌文字 [UMSocialSnsService presentSnsIconSheetView:self appKey:@"5edaacbe978eea085d11d331" shareText:shareText shareImage:shareImage shareToSnsNames:type delegate:self]; return; } - (UIImage *)createNonInterpolatedUIImageFromCIImage:(CIImage *)image WithSize:(CGFloat)size { CGRect extent = CGRectIntegral(image.extent); CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent)); //创建bitmap size_t width = CGRectGetWidth(extent)*scale; size_t height = CGRectGetHeight(extent)*scale; CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray(); CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone); CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef bitmapImage = [context createCGImage:image fromRect:extent]; CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone); CGContextScaleCTM(bitmapRef, scale, scale); CGContextDrawImage(bitmapRef, extent, bitmapImage); //保存图片 CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef); CGContextRelease(bitmapRef); CGImageRelease(bitmapImage); return [UIImage imageWithCGImage:scaledImage]; } #pragma mark -- <保存到相册> -(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { NSString *msg = nil ; if(error){ msg = @"保存图片失败" ; }else{ msg = @"保存图片成功" ; } } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; } @end