123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- //
- // JXShareMVc.m
- // shiku_im
- //
- // Created by os on 2020/7/7.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXShareMVc.h"
- #import "UMSocialSnsService.h"
- #import "UMSocialSnsPlatformManager.h"
- #import "MyButton.h"
- @interface JXShareMVc ()
- @property (weak, nonatomic) IBOutlet UIButton *inviteBtn;
- @property (weak, nonatomic) IBOutlet UIImageView *shareIMG;
- @property (weak, nonatomic) IBOutlet UIImageView *topIMGView;
- @property (weak, nonatomic) IBOutlet UIImageView *shareKIMG;
- @end
- @implementation JXShareMVc
- - (IBAction)backBtn:(id)sender {
-
- [g_navigation dismissViewController:self animated:YES];
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- 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];
- [bottomBtn addTarget:self action:@selector(saveBttIMG1:) forControlEvents:UIControlEventTouchUpInside];
- [_shareKIMG addSubview:bottomBtn];
-
- //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(1+i*((JX_SCREEN_WIDTH-60)/4));
- make.width.mas_equalTo((JX_SCREEN_WIDTH-60)/4);
- // make.height.mas_equalTo(60);
- make.top.mas_equalTo(1);
- }];
-
-
- }
-
-
-
-
- UISwipeGestureRecognizer *recognizer2 = [[UISwipeGestureRecognizer alloc]
- initWithTarget:self
- action:@selector(foundSwipe2:)];
- recognizer2.direction =UISwipeGestureRecognizerDirectionDown;
- [_topIMGView addGestureRecognizer:recognizer2];
- [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];
-
-
-
- }
- - (void)foundSwipe:(UISwipeGestureRecognizer *)sender {
-
- CGRect bounds=_shareIMG.bounds;
- bounds.origin.y=110;
-
- _shareIMG.bounds=bounds;
-
- }
- - (void)foundSwipe2:(UISwipeGestureRecognizer *)sender {
-
- //设置识别滑动方向
- sender.direction =UISwipeGestureRecognizerDirectionDown;
- //Swipe手势识别器关联到View
- [self.view addGestureRecognizer:sender];
-
- CGRect bounds=self.view.bounds;
- bounds.origin.y=0;
-
- _shareIMG.bounds=bounds;
-
- }
- #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.shaview.inviteBtn setImage:img forState:UIControlStateNormal] ;
-
- }
- else if([aDownload.action isEqualToString:act_getinviteget])
- {
- NSDictionary *dictM=dict;
- NSString *str=[NSString stringWithFormat:@" 邀请码:%@ ",dictM[@"invite"]];
- [self.inviteBtn 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{
- [SVProgressHUD showWithStatus:@"保存成功"];
- [SVProgressHUD dismissWithDelay:1.0];
-
-
- msg = @"保存图片成功" ;
- }
- }
- @end
|