123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- //
- // LDPushToWeixViewController.m
- // YouHuiProject
- //
- // Created by 王奥东 on 2018/11/13.
- // Copyright © 2018 kuxuan. All rights reserved.
- //
- #import "LDPushToWeixViewController.h"
- #import <WXApi.h>
- #import "HYUMShareManager.h"
- #import <AssetsLibrary/AssetsLibrary.h>
- #import "LDShareManager.h"
- #import "LDAuthorityManager.h"
- #import <Photos/Photos.h>
- @interface LDPushToWeixViewController ()<UITableViewDelegate,UITableViewDataSource>{
- NSString *_weChatStr;
- NSInteger _showType;//1注册 2客服
- ActivityIndicatorView *_indicatorView;
-
- }
- @property(nonatomic, strong)UILabel *detailLabel;//“添加专属客服微信,了解更多赚钱秘籍”
- @property(nonatomic, strong)UIImageView *icon;//图标
- @property(nonatomic, strong)UILabel *userName;//用户名称
- @property(nonatomic, strong)UILabel *userWeixin;//用户微信号
- @property(nonatomic, strong)UILabel *noteLabel;//非专属客服的提醒
- @property(nonatomic, strong)UILabel *InviteCardLabel;//添加邀请码的提示
- @property(nonatomic, strong)UIButton *weixinNumebrButton;//复制微信号
- @property(nonatomic, strong)UIButton *pushWeixinButton;//跳转到微信
- @property(nonatomic, strong)UIButton *leftBtn;//返回,除注册时显示返回按钮
- @property(nonatomic, strong)UIButton *rightJump;//跳过,注册时显示跳过按钮
- //二维码
- @property(nonatomic,strong)UIImageView *codeImgv;
- @property(nonatomic, strong)UIButton *savecodeBtn;//保存二维码
- @property(nonatomic, strong)UIButton *copysBtn;//复制
- @property(nonatomic, strong) UITableView *tableView;
- @end
- @implementation LDPushToWeixViewController
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.view.backgroundColor = [UIColor whiteColor];
- self.detailLabel = [[UILabel alloc] init];
- [self.view addSubview:self.detailLabel];
-
- self.detailLabel.text = @"我是你的专属客服,添加微信好友可:";
- self.detailLabel.textColor = [UIColor YHColorWithHex:0x000000];
- self.detailLabel.font = [UIFont systemFontOfSize:FITSIZE(15)];
-
- self.icon = [[UIImageView alloc] init];
- [self.view addSubview:self.icon];
- self.icon.backgroundColor=[UIColor backgroudColor];
- self.icon.layer.cornerRadius=FITSIZE(20);
- self.icon.layer.masksToBounds=YES;
- [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.view).mas_offset(FITSIZE(103));
- make.left.mas_equalTo(FITSIZE(26));
- make.width.height.mas_equalTo(FITSIZE(40));
- }];
- [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.mas_equalTo(self.view).mas_offset(FITSIZE(103));
- make.width.mas_greaterThanOrEqualTo(FITSIZE(120));
- make.height.mas_greaterThanOrEqualTo(FITSIZE(40));
- make.left.mas_equalTo(self.icon.mas_right).mas_offset(FITSIZE(16));
- }];
-
-
-
-
- //添加二维码
- self.codeImgv =[[UIImageView alloc]init];
- self.codeImgv.backgroundColor =[UIColor backgroudColor];
-
- [self.view addSubview:self.codeImgv];
- [self.codeImgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.height.mas_equalTo(FITSIZE(153));
- make.centerX.mas_equalTo(self.view);
- make.top.mas_equalTo(217);
- }];
-
-
- self.savecodeBtn =[[UIButton alloc]init];
- self.savecodeBtn.backgroundColor =[UIColor homeRedColor];
- self.savecodeBtn.layer.cornerRadius=FITSIZE(4);
- self.savecodeBtn.layer.masksToBounds=YES;
- [self.savecodeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.savecodeBtn.titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
- [self.savecodeBtn setTitle:@"保存二维码到手机" forState:UIControlStateNormal];
- [self.savecodeBtn addTarget:self action:@selector(saveCodePhone) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.savecodeBtn];
-
- [self.savecodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.view);
- make.top.mas_equalTo(self.codeImgv.mas_bottom).mas_offset(FITSIZE(38));
- make.width.mas_equalTo(FITSIZE(223));
- make.height.mas_offset(FITSIZE(37));
- }];
-
- self.copysBtn =[[UIButton alloc]init];
- self.copysBtn.backgroundColor =[UIColor homeRedColor];
- self.copysBtn.layer.cornerRadius=FITSIZE(4);
- self.copysBtn.layer.masksToBounds=YES;
- [self.copysBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.copysBtn.titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
- [self.copysBtn setTitle:@"复制微信号打开微信" forState:UIControlStateNormal];
- [self.view addSubview:self.copysBtn];
- [self.copysBtn addTarget:self action:@selector(pushToWeixin) forControlEvents:UIControlEventTouchUpInside];
- [self.copysBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.view);
- make.top.mas_equalTo(self.savecodeBtn.mas_top).mas_offset(FITSIZE(50));
- make.width.mas_equalTo(FITSIZE(223));
- make.height.mas_offset(FITSIZE(37));
- }];
- self.userWeixin = [[UILabel alloc] init];
- self.userWeixin.textColor = [UIColor YHColorWithHex:0x000000];
- self.userWeixin.font = [UIFont systemFontOfSize:FITSIZE(13)];
- self.userWeixin.textAlignment=NSTextAlignmentCenter;
- [self.view addSubview:self.userWeixin];
-
- [self.userWeixin mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.view);
- make.top.mas_equalTo(self.copysBtn.mas_bottom).mas_offset(FITSIZE(8));
- make.width.mas_greaterThanOrEqualTo(FITSIZE(124));
- make.height.mas_greaterThanOrEqualTo(FITSIZE(18));
- }];
- [self setNavBar];
- [self initHUD];
- [self requestDetail];
-
-
- // [self getNetworkerWithPushWeixin];
- }
- - (void)initHUD {
- ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
- _indicatorView = indicatorView;
- [_indicatorView startAnimating];
-
- }
- //请求
- -(void)requestDetail
- {
-
- NSString *url= [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/belongToYou",BaseURL];
- [LDHttp post:url params:nil success:^(id json) {
- [self.icon sd_setImageWithURL:[NSURL URLWithString:json[@"headimgurl"]]];
- [self.codeImgv sd_setImageWithURL:[NSURL URLWithString:json[@"qrcode"]]];
- if (![json[@"wechat"] isKindOfClass:[NSNull class]]) {
- self.userWeixin.text=[NSString stringWithFormat:@"微信号:%@",json[@"wechat"]];
- _weChatStr =json[@"wechat"];
- }
-
-
-
-
- NSArray *array =json[@"text"];
- for (int i =0 ;i<array.count ; i++) {
- UIImageView *imgv =[[UIImageView alloc]init];
- imgv.image =[UIImage imageNamed:@"kefu_icon"];
- [self.view addSubview:imgv];
- UILabel *label =[[UILabel alloc]init];
- label.font =[UIFont systemFontOfSize:FITSIZE(17)];
- [self.view addSubview:label];
- label.textColor=[UIColor YHColorWithHex:0x000000];
- label.text=array[i];
- CGFloat heights =i*FITSIZE(30)+FITSIZE(164);
- [imgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.view).mas_offset(heights);
- make.width.height.mas_equalTo(FITSIZE(16));
- make.left.mas_equalTo(FITSIZE(104));
- }];
- CGFloat labelheights =i*FITSIZE(31)+FITSIZE(160);
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.mas_equalTo(self.view).mas_offset(labelheights);
- make.height.mas_equalTo(FITSIZE(21));
- make.width.mas_equalTo(FITSIZE(200));
- make.left.mas_equalTo(FITSIZE(127));
- }];
-
-
- }
- CGFloat codeHeight=array.count*FITSIZE(31)+FITSIZE(200);
- [self.codeImgv mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(codeHeight);
- }];
- [self.savecodeBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.codeImgv.mas_bottom).mas_offset(FITSIZE(38));
- }];
- [self.copysBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.savecodeBtn.mas_top).mas_offset(FITSIZE(50));
- }];
- [self.userWeixin mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.copysBtn.mas_bottom).mas_offset(FITSIZE(8));
- }];
- self.codeImgv.hidden=NO;
- self.savecodeBtn.hidden=NO;
- self.copysBtn.hidden=NO;
- self.userWeixin.hidden=NO;
- if ([json[@"qrcode"] length]==0 && [json[@"wechat"] length]==0) {//二维码和微信号都为空
- self.codeImgv.hidden=YES;
- self.savecodeBtn.hidden=YES;
- self.copysBtn.hidden=YES;
- self.userWeixin.hidden=YES;
- }else{
- if ([json[@"qrcode"] length]==0) {//二维码为空
- self.codeImgv.hidden=YES;
- self.savecodeBtn.hidden=YES;
- [self.copysBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(codeHeight);
- }];
- [self.userWeixin mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.codeImgv.mas_bottom).mas_offset(FITSIZE(38));
- }];
- }
- if (![json[@"wechat"] isKindOfClass:[NSNull class]]) {
- if ([json[@"wechat"] length]==0) {//微信号为空
- self.copysBtn.hidden=YES;
- self.userWeixin.hidden=YES;
-
- }
- }
-
- }
-
- [_indicatorView stopAnimating];
- } failure:^(NSError *error) {
- [_indicatorView stopAnimating];
- }];
- }
- #pragma mark--保存二维码到手机
- -(void)saveCodePhone
- {
- UIImage *img =[self changeToImage];
-
- [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
- if (status == PHAuthorizationStatusAuthorized) {
- //允许使用相册
- if (img) {
- __block ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
- [lib writeImageToSavedPhotosAlbum:img.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
- if (error) {
- [SVProgressHUD showErrorWithStatus:@"保存失败"];
- }else {
- [SVProgressHUD showSuccessWithStatus:@"保存成功"];
- }
- lib = nil;
- }];
- }else {
- [SVProgressHUD showErrorWithStatus:@"图片生成中"];
- }
- }else{
- //不允许使用相册
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您还没有开启访问相册权限" preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [alertController dismissViewControllerAnimated:YES completion:nil];
- [self gotoSetting];
- }];
- UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [alertController dismissViewControllerAnimated:YES completion:nil];
- }];
- [alertController addAction:action1];
- [alertController addAction:action2];
- alertController.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:alertController animated:YES completion:nil];
-
- }
- }];
- }
- - (void)gotoSetting {
- NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
- if([[UIApplication sharedApplication]canOpenURL:url] ) {
- if (@available(iOS 10.0, *)) {
- [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) {
- }];
- } else {
- [[UIApplication sharedApplication]openURL:url];
- }
- }
- }
- -(void)setNavBar {
-
- [self.navigationBar setNavTitle:@"专属客服"];
- self.navigationBar.backgroundColor = [UIColor changeColor];
- self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
-
-
- NSArray *viewControllers = self.navigationController.viewControllers;
- if (viewControllers.count < 1) {//present进入
-
- [self.leftBtn removeFromSuperview];
- self.leftBtn = nil;
-
- // self.InviteCardLabel = [[UILabel alloc] init];
- // [self.view addSubview:self.InviteCardLabel];
- // [self.InviteCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- //
- // make.top.mas_equalTo(self.pushWeixinButton.mas_bottom).mas_offset(FITSIZE(14));
- // m+ake.width.mas_equalTo(SCREEN_WIDTH);
- // make.height.mas_greaterThanOrEqualTo(FITSIZE(13));
- // }];
- // self.InviteCardLabel.textAlignment = NSTextAlignmentCenter;
- // self.InviteCardLabel.text = @"温馨提示:您也可以在【个人中心】【专属客服】中添加专属客服微信喔";
- // self.InviteCardLabel.font = [UIFont systemFontOfSize:FITSIZE(9)];
- // self.InviteCardLabel.textColor = [UIColor YHColorWithHex:0x9B9B9B];
-
- self.rightJump = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-53, 0, 40, 40)];
- [self.rightJump setTitle:@"跳过" forState:UIControlStateNormal];
- [self.rightJump addTarget:self action:@selector(jumpAction) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomRightButtons:@[self.rightJump]];
- _showType = 1;
- }else {//push进入
- [self.InviteCardLabel removeFromSuperview];
- self.InviteCardLabel = nil;
- [self.rightJump removeFromSuperview];
- self.rightJump = nil;
-
- self.leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [self.leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
- [self.leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomLeftButtons:@[self.leftBtn]];
- _showType = 2;
- }
- }
- #pragma mark-跳转微信
- -(void)pushToWeixin {
- NSString *str = @"weixin://";
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = _weChatStr;
-
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
- if (_showType == 1) {
- [MobClick event:ExclusiveServiceCopy label:@"2-注册"];
- }else {
- [MobClick event:ExclusiveServiceCopy label:@"2-客服"];
- }
-
- }
- -(void)backAction {
-
- [self.navigationController popViewControllerAnimated:YES];
- if (_showType == 1) {
- [MobClick event:ExclusiveServiceOpen label:@"2-注册"];
- }else {
- [MobClick event:ExclusiveServiceOpen label:@"2-客服"];
- }
-
- }
- -(void)jumpAction {
-
- [self dismissViewControllerAnimated:NO completion:nil];
- }
- -(UIImage *)changeToImage{
-
- CGSize s = CGSizeMake(FITSIZE(153), FITSIZE(153));
- // 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
- // UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
- UIGraphicsBeginImageContextWithOptions(s, NO, 0);
- [self.codeImgv.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return image;
- }
- @end
|