猎豆优选

LDPushToWeixViewController.m 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. //
  2. // LDPushToWeixViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 王奥东 on 2018/11/13.
  6. // Copyright © 2018 kuxuan. All rights reserved.
  7. //
  8. #import "LDPushToWeixViewController.h"
  9. #import <WXApi.h>
  10. #import "HYUMShareManager.h"
  11. #import <AssetsLibrary/AssetsLibrary.h>
  12. #import "LDShareManager.h"
  13. #import "LDAuthorityManager.h"
  14. #import <Photos/Photos.h>
  15. @interface LDPushToWeixViewController ()<UITableViewDelegate,UITableViewDataSource>{
  16. NSString *_weChatStr;
  17. NSInteger _showType;//1注册 2客服
  18. ActivityIndicatorView *_indicatorView;
  19. }
  20. @property(nonatomic, strong)UILabel *detailLabel;//“添加专属客服微信,了解更多赚钱秘籍”
  21. @property(nonatomic, strong)UIImageView *icon;//图标
  22. @property(nonatomic, strong)UILabel *userName;//用户名称
  23. @property(nonatomic, strong)UILabel *userWeixin;//用户微信号
  24. @property(nonatomic, strong)UILabel *noteLabel;//非专属客服的提醒
  25. @property(nonatomic, strong)UILabel *InviteCardLabel;//添加邀请码的提示
  26. @property(nonatomic, strong)UIButton *weixinNumebrButton;//复制微信号
  27. @property(nonatomic, strong)UIButton *pushWeixinButton;//跳转到微信
  28. @property(nonatomic, strong)UIButton *leftBtn;//返回,除注册时显示返回按钮
  29. @property(nonatomic, strong)UIButton *rightJump;//跳过,注册时显示跳过按钮
  30. //二维码
  31. @property(nonatomic,strong)UIImageView *codeImgv;
  32. @property(nonatomic, strong)UIButton *savecodeBtn;//保存二维码
  33. @property(nonatomic, strong)UIButton *copysBtn;//复制
  34. @property(nonatomic, strong) UITableView *tableView;
  35. @end
  36. @implementation LDPushToWeixViewController
  37. - (void)viewWillAppear:(BOOL)animated {
  38. [super viewWillAppear:animated];
  39. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  40. }
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. self.view.backgroundColor = [UIColor whiteColor];
  44. self.detailLabel = [[UILabel alloc] init];
  45. [self.view addSubview:self.detailLabel];
  46. self.detailLabel.text = @"我是你的专属客服,添加微信好友可:";
  47. self.detailLabel.textColor = [UIColor YHColorWithHex:0x000000];
  48. self.detailLabel.font = [UIFont systemFontOfSize:FITSIZE(15)];
  49. self.icon = [[UIImageView alloc] init];
  50. [self.view addSubview:self.icon];
  51. self.icon.backgroundColor=[UIColor backgroudColor];
  52. self.icon.layer.cornerRadius=FITSIZE(20);
  53. self.icon.layer.masksToBounds=YES;
  54. [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.mas_equalTo(self.view).mas_offset(FITSIZE(103));
  56. make.left.mas_equalTo(FITSIZE(26));
  57. make.width.height.mas_equalTo(FITSIZE(40));
  58. }];
  59. [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.mas_equalTo(self.view).mas_offset(FITSIZE(103));
  61. make.width.mas_greaterThanOrEqualTo(FITSIZE(120));
  62. make.height.mas_greaterThanOrEqualTo(FITSIZE(40));
  63. make.left.mas_equalTo(self.icon.mas_right).mas_offset(FITSIZE(16));
  64. }];
  65. //添加二维码
  66. self.codeImgv =[[UIImageView alloc]init];
  67. self.codeImgv.backgroundColor =[UIColor backgroudColor];
  68. [self.view addSubview:self.codeImgv];
  69. [self.codeImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.width.height.mas_equalTo(FITSIZE(153));
  71. make.centerX.mas_equalTo(self.view);
  72. make.top.mas_equalTo(217);
  73. }];
  74. self.savecodeBtn =[[UIButton alloc]init];
  75. self.savecodeBtn.backgroundColor =[UIColor homeRedColor];
  76. self.savecodeBtn.layer.cornerRadius=FITSIZE(4);
  77. self.savecodeBtn.layer.masksToBounds=YES;
  78. [self.savecodeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  79. self.savecodeBtn.titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
  80. [self.savecodeBtn setTitle:@"保存二维码到手机" forState:UIControlStateNormal];
  81. [self.savecodeBtn addTarget:self action:@selector(saveCodePhone) forControlEvents:UIControlEventTouchUpInside];
  82. [self.view addSubview:self.savecodeBtn];
  83. [self.savecodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.centerX.mas_equalTo(self.view);
  85. make.top.mas_equalTo(self.codeImgv.mas_bottom).mas_offset(FITSIZE(38));
  86. make.width.mas_equalTo(FITSIZE(223));
  87. make.height.mas_offset(FITSIZE(37));
  88. }];
  89. self.copysBtn =[[UIButton alloc]init];
  90. self.copysBtn.backgroundColor =[UIColor homeRedColor];
  91. self.copysBtn.layer.cornerRadius=FITSIZE(4);
  92. self.copysBtn.layer.masksToBounds=YES;
  93. [self.copysBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  94. self.copysBtn.titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
  95. [self.copysBtn setTitle:@"复制微信号打开微信" forState:UIControlStateNormal];
  96. [self.view addSubview:self.copysBtn];
  97. [self.copysBtn addTarget:self action:@selector(pushToWeixin) forControlEvents:UIControlEventTouchUpInside];
  98. [self.copysBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.centerX.mas_equalTo(self.view);
  100. make.top.mas_equalTo(self.savecodeBtn.mas_top).mas_offset(FITSIZE(50));
  101. make.width.mas_equalTo(FITSIZE(223));
  102. make.height.mas_offset(FITSIZE(37));
  103. }];
  104. self.userWeixin = [[UILabel alloc] init];
  105. self.userWeixin.textColor = [UIColor YHColorWithHex:0x000000];
  106. self.userWeixin.font = [UIFont systemFontOfSize:FITSIZE(13)];
  107. self.userWeixin.textAlignment=NSTextAlignmentCenter;
  108. [self.view addSubview:self.userWeixin];
  109. [self.userWeixin mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.centerX.mas_equalTo(self.view);
  111. make.top.mas_equalTo(self.copysBtn.mas_bottom).mas_offset(FITSIZE(8));
  112. make.width.mas_greaterThanOrEqualTo(FITSIZE(124));
  113. make.height.mas_greaterThanOrEqualTo(FITSIZE(18));
  114. }];
  115. [self setNavBar];
  116. [self initHUD];
  117. [self requestDetail];
  118. // [self getNetworkerWithPushWeixin];
  119. }
  120. - (void)initHUD {
  121. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  122. _indicatorView = indicatorView;
  123. [_indicatorView startAnimating];
  124. }
  125. //请求
  126. -(void)requestDetail
  127. {
  128. NSString *url= [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/belongToYou",BaseURL];
  129. [LDHttp post:url params:nil success:^(id json) {
  130. [self.icon sd_setImageWithURL:[NSURL URLWithString:json[@"headimgurl"]]];
  131. [self.codeImgv sd_setImageWithURL:[NSURL URLWithString:json[@"qrcode"]]];
  132. if (![json[@"wechat"] isKindOfClass:[NSNull class]]) {
  133. self.userWeixin.text=[NSString stringWithFormat:@"微信号:%@",json[@"wechat"]];
  134. _weChatStr =json[@"wechat"];
  135. }
  136. NSArray *array =json[@"text"];
  137. for (int i =0 ;i<array.count ; i++) {
  138. UIImageView *imgv =[[UIImageView alloc]init];
  139. imgv.image =[UIImage imageNamed:@"kefu_icon"];
  140. [self.view addSubview:imgv];
  141. UILabel *label =[[UILabel alloc]init];
  142. label.font =[UIFont systemFontOfSize:FITSIZE(17)];
  143. [self.view addSubview:label];
  144. label.textColor=[UIColor YHColorWithHex:0x000000];
  145. label.text=array[i];
  146. CGFloat heights =i*FITSIZE(30)+FITSIZE(164);
  147. [imgv mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.top.mas_equalTo(self.view).mas_offset(heights);
  149. make.width.height.mas_equalTo(FITSIZE(16));
  150. make.left.mas_equalTo(FITSIZE(104));
  151. }];
  152. CGFloat labelheights =i*FITSIZE(31)+FITSIZE(160);
  153. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  154. make.top.mas_equalTo(self.view).mas_offset(labelheights);
  155. make.height.mas_equalTo(FITSIZE(21));
  156. make.width.mas_equalTo(FITSIZE(200));
  157. make.left.mas_equalTo(FITSIZE(127));
  158. }];
  159. }
  160. CGFloat codeHeight=array.count*FITSIZE(31)+FITSIZE(200);
  161. [self.codeImgv mas_updateConstraints:^(MASConstraintMaker *make) {
  162. make.top.mas_equalTo(codeHeight);
  163. }];
  164. [self.savecodeBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  165. make.top.mas_equalTo(self.codeImgv.mas_bottom).mas_offset(FITSIZE(38));
  166. }];
  167. [self.copysBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  168. make.top.mas_equalTo(self.savecodeBtn.mas_top).mas_offset(FITSIZE(50));
  169. }];
  170. [self.userWeixin mas_updateConstraints:^(MASConstraintMaker *make) {
  171. make.top.mas_equalTo(self.copysBtn.mas_bottom).mas_offset(FITSIZE(8));
  172. }];
  173. self.codeImgv.hidden=NO;
  174. self.savecodeBtn.hidden=NO;
  175. self.copysBtn.hidden=NO;
  176. self.userWeixin.hidden=NO;
  177. if ([json[@"qrcode"] length]==0 && [json[@"wechat"] length]==0) {//二维码和微信号都为空
  178. self.codeImgv.hidden=YES;
  179. self.savecodeBtn.hidden=YES;
  180. self.copysBtn.hidden=YES;
  181. self.userWeixin.hidden=YES;
  182. }else{
  183. if ([json[@"qrcode"] length]==0) {//二维码为空
  184. self.codeImgv.hidden=YES;
  185. self.savecodeBtn.hidden=YES;
  186. [self.copysBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  187. make.top.mas_equalTo(codeHeight);
  188. }];
  189. [self.userWeixin mas_updateConstraints:^(MASConstraintMaker *make) {
  190. make.top.mas_equalTo(self.codeImgv.mas_bottom).mas_offset(FITSIZE(38));
  191. }];
  192. }
  193. if (![json[@"wechat"] isKindOfClass:[NSNull class]]) {
  194. if ([json[@"wechat"] length]==0) {//微信号为空
  195. self.copysBtn.hidden=YES;
  196. self.userWeixin.hidden=YES;
  197. }
  198. }
  199. }
  200. [_indicatorView stopAnimating];
  201. } failure:^(NSError *error) {
  202. [_indicatorView stopAnimating];
  203. }];
  204. }
  205. #pragma mark--保存二维码到手机
  206. -(void)saveCodePhone
  207. {
  208. UIImage *img =[self changeToImage];
  209. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
  210. if (status == PHAuthorizationStatusAuthorized) {
  211. //允许使用相册
  212. if (img) {
  213. __block ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
  214. [lib writeImageToSavedPhotosAlbum:img.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
  215. if (error) {
  216. [SVProgressHUD showErrorWithStatus:@"保存失败"];
  217. }else {
  218. [SVProgressHUD showSuccessWithStatus:@"保存成功"];
  219. }
  220. lib = nil;
  221. }];
  222. }else {
  223. [SVProgressHUD showErrorWithStatus:@"图片生成中"];
  224. }
  225. }else{
  226. //不允许使用相册
  227. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您还没有开启访问相册权限" preferredStyle:UIAlertControllerStyleAlert];
  228. UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  229. [alertController dismissViewControllerAnimated:YES completion:nil];
  230. [self gotoSetting];
  231. }];
  232. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  233. [alertController dismissViewControllerAnimated:YES completion:nil];
  234. }];
  235. [alertController addAction:action1];
  236. [alertController addAction:action2];
  237. alertController.modalPresentationStyle = UIModalPresentationFullScreen;
  238. [self presentViewController:alertController animated:YES completion:nil];
  239. }
  240. }];
  241. }
  242. - (void)gotoSetting {
  243. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  244. if([[UIApplication sharedApplication]canOpenURL:url] ) {
  245. if (@available(iOS 10.0, *)) {
  246. [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) {
  247. }];
  248. } else {
  249. [[UIApplication sharedApplication]openURL:url];
  250. }
  251. }
  252. }
  253. -(void)setNavBar {
  254. [self.navigationBar setNavTitle:@"专属客服"];
  255. self.navigationBar.backgroundColor = [UIColor changeColor];
  256. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  257. NSArray *viewControllers = self.navigationController.viewControllers;
  258. if (viewControllers.count < 1) {//present进入
  259. [self.leftBtn removeFromSuperview];
  260. self.leftBtn = nil;
  261. // self.InviteCardLabel = [[UILabel alloc] init];
  262. // [self.view addSubview:self.InviteCardLabel];
  263. // [self.InviteCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  264. //
  265. // make.top.mas_equalTo(self.pushWeixinButton.mas_bottom).mas_offset(FITSIZE(14));
  266. // m+ake.width.mas_equalTo(SCREEN_WIDTH);
  267. // make.height.mas_greaterThanOrEqualTo(FITSIZE(13));
  268. // }];
  269. // self.InviteCardLabel.textAlignment = NSTextAlignmentCenter;
  270. // self.InviteCardLabel.text = @"温馨提示:您也可以在【个人中心】【专属客服】中添加专属客服微信喔";
  271. // self.InviteCardLabel.font = [UIFont systemFontOfSize:FITSIZE(9)];
  272. // self.InviteCardLabel.textColor = [UIColor YHColorWithHex:0x9B9B9B];
  273. self.rightJump = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-53, 0, 40, 40)];
  274. [self.rightJump setTitle:@"跳过" forState:UIControlStateNormal];
  275. [self.rightJump addTarget:self action:@selector(jumpAction) forControlEvents:UIControlEventTouchUpInside];
  276. [self.navigationBar setCustomRightButtons:@[self.rightJump]];
  277. _showType = 1;
  278. }else {//push进入
  279. [self.InviteCardLabel removeFromSuperview];
  280. self.InviteCardLabel = nil;
  281. [self.rightJump removeFromSuperview];
  282. self.rightJump = nil;
  283. self.leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  284. [self.leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  285. [self.leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  286. [self.navigationBar setCustomLeftButtons:@[self.leftBtn]];
  287. _showType = 2;
  288. }
  289. }
  290. #pragma mark-跳转微信
  291. -(void)pushToWeixin {
  292. NSString *str = @"weixin://";
  293. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  294. pasteboard.string = _weChatStr;
  295. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
  296. if (_showType == 1) {
  297. [MobClick event:ExclusiveServiceCopy label:@"2-注册"];
  298. }else {
  299. [MobClick event:ExclusiveServiceCopy label:@"2-客服"];
  300. }
  301. }
  302. -(void)backAction {
  303. [self.navigationController popViewControllerAnimated:YES];
  304. if (_showType == 1) {
  305. [MobClick event:ExclusiveServiceOpen label:@"2-注册"];
  306. }else {
  307. [MobClick event:ExclusiveServiceOpen label:@"2-客服"];
  308. }
  309. }
  310. -(void)jumpAction {
  311. [self dismissViewControllerAnimated:NO completion:nil];
  312. }
  313. -(UIImage *)changeToImage{
  314. CGSize s = CGSizeMake(FITSIZE(153), FITSIZE(153));
  315. // 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
  316. // UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
  317. UIGraphicsBeginImageContextWithOptions(s, NO, 0);
  318. [self.codeImgv.layer renderInContext:UIGraphicsGetCurrentContext()];
  319. UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
  320. UIGraphicsEndImageContext();
  321. return image;
  322. }
  323. @end