Brak opisu

LFWSettingViewController.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. //
  2. // LFWSettingViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LFWSettingViewController.h"
  9. #import "LFWAuthorityManager.h"
  10. #import "CCActionSheet.h"
  11. #import <AlibabaAuthSDK/ALBBSession.h>
  12. #import <AlibabaAuthSDK/ALBBSDK.h>
  13. #import "DXAlertView.h"
  14. #import "LFWLoginViewController.h"
  15. #import <StoreKit/StoreKit.h>
  16. @interface LFWSettingViewController ()<UITableViewDelegate,UITableViewDataSource,CCActionSheetDelegate,DXAlertViewDelegate>
  17. @property (nonatomic, strong) UITableView *tableView;
  18. @property (nonatomic, strong) NSArray *dataArr;
  19. @property (nonatomic, strong) NSArray *sexArr;
  20. @end
  21. @implementation LFWSettingViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self configNavigationBar];
  25. [self addObserToController];
  26. }
  27. - (void)configNavigationBar {
  28. self.view.backgroundColor = [UIColor whiteColor];
  29. [self.navigationBar setNavTitle:@"设置"];
  30. self.navigationBar.showNavigationBarBottomLine = YES;
  31. [self.view addSubview:self.tableView];
  32. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  33. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  34. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  35. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  36. UILabel *logOut = [[UILabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-50-BottomMargin, SCREEN_WIDTH, 50)];
  37. logOut.backgroundColor = [UIColor whiteColor];
  38. logOut.textColor = [UIColor homeRedColor];
  39. logOut.textAlignment = NSTextAlignmentCenter;
  40. logOut.font = [UIFont systemFontOfSize:14];
  41. logOut.text = [AccountTool isLogin] ? @"退出登录":@"快速登录";
  42. logOut.userInteractionEnabled = YES;
  43. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(logOutAction)];
  44. [logOut addGestureRecognizer:tap];
  45. [self.view addSubview:logOut];}
  46. - (void)addObserToController {
  47. [[NSNotificationCenter defaultCenter] addObserver:self
  48. selector:@selector(becomActive)
  49. name:UIApplicationDidBecomeActiveNotification object:nil];
  50. }
  51. - (void)becomActive {
  52. [self.tableView reloadData];
  53. }
  54. /**
  55. 返回
  56. */
  57. - (void)backAction {
  58. [self.navigationController popViewControllerAnimated:YES];
  59. }
  60. /**
  61. 退出登录
  62. */
  63. - (void)logOutAction {
  64. if ([AccountTool isLogin]) {
  65. // DXAlertView *alert = [[DXAlertView alloc] initWithTitle:@"温馨提示" message:@"是否要退出登录?" cancelBtnTitle:@"取消" otherBtnTitle:@"确定"];
  66. // alert.clickBlock = ^(NSInteger index) {
  67. // if (index == 1) {
  68. // [self logOutManager];
  69. // }
  70. // };
  71. // [alert show];
  72. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否要退出登录?" preferredStyle:UIAlertControllerStyleAlert];
  73. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  74. }];
  75. UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  76. [self logOutManager];
  77. }];
  78. [alert addAction:cancel];
  79. [alert addAction:sure];
  80. [self presentViewController:alert animated:YES completion:nil];
  81. }else {
  82. LFWLoginViewController *login = [[LFWLoginViewController alloc] init];
  83. [self presentViewController:login animated:YES completion:nil];
  84. }
  85. }
  86. - (void)logOutManager {
  87. [LFWHttp post:Logout params:nil success:^(id json) {
  88. [AccountTool deleteAccount];
  89. [self.navigationController popViewControllerAnimated:YES];
  90. } failure:^(NSError *error) {
  91. }];
  92. }
  93. /**
  94. switch 点击
  95. */
  96. - (void)switchAction {
  97. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  98. if([[UIApplication sharedApplication]canOpenURL:url] ) {
  99. if (@available(iOS 10.0, *)) {
  100. [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) {
  101. }];
  102. } else {
  103. [[UIApplication sharedApplication]openURL:url];
  104. }
  105. }
  106. }
  107. #pragma mark ------------------
  108. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  109. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  110. [cell setSeparatorInset:UIEdgeInsetsMake(0, 50, 0, 0)];
  111. }
  112. }
  113. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  114. return self.dataArr.count;
  115. }
  116. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  117. return 50;
  118. }
  119. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  120. return 0.1;
  121. }
  122. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  123. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
  124. cell.textLabel.text = self.dataArr[indexPath.row][@"title"];
  125. if (indexPath.row != 0) {
  126. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  127. }
  128. // if (indexPath.row == 0) {
  129. // NSString *sex = [[NSUserDefaults standardUserDefaults] objectForKey:UserSexKey];
  130. //
  131. // cell.detailTextLabel.text = [sex isEqualToString:@"0"] ? @"女":@"男";
  132. // }
  133. if (indexPath.row == 0) {
  134. UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 10, 50, 30)];
  135. [switchView addTarget:self action:@selector(switchAction) forControlEvents:UIControlEventTouchUpInside]; // 开关事件切换通知
  136. [cell addSubview:switchView];
  137. if ([LFWAuthorityManager isObtainUserNotificationAuthority]) {
  138. switchView.on = YES;
  139. }else {
  140. switchView.on = NO;
  141. }
  142. }
  143. if (indexPath.row == 1) {
  144. NSUInteger intg = [[SDImageCache sharedImageCache] getSize];
  145. NSString * currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeWithInterge:intg]];
  146. cell.detailTextLabel.text = currentVolum;
  147. }
  148. if (indexPath.row == 2) {
  149. if ([[ALBBSession sharedInstance] isLogin]) {
  150. cell.detailTextLabel.text = @"已授权";
  151. }else {
  152. cell.detailTextLabel.text = @"未授权";
  153. }
  154. }
  155. NSString *imgName = self.dataArr[indexPath.row][@"image"];
  156. cell.imageView.image = [UIImage imageNamed:imgName];
  157. cell.textLabel.font = [UIFont systemFontOfSize:15];
  158. cell.textLabel.textColor = [UIColor YHColorWithHex:0x666666];
  159. cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
  160. cell.detailTextLabel.textColor = [UIColor YHColorWithHex:0x999999];
  161. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  162. return cell;
  163. }
  164. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  165. // if (indexPath.row == 0) {
  166. // //改变性别
  167. // [self changeUserSex];
  168. // }
  169. if (indexPath.row == 1) {
  170. //清理缓存
  171. [self clearCacheWith:indexPath];
  172. }
  173. if (indexPath.row == 2) {
  174. //淘宝授权
  175. [self taobaoAuthor];
  176. }
  177. }
  178. #pragma mark ------------ private----------
  179. /**
  180. 改变性别
  181. */
  182. - (void)changeUserSex {
  183. CCActionSheet *actionSheet = [[CCActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:self.sexArr];
  184. [actionSheet showInView:self.view];
  185. }
  186. /**
  187. 清理缓存
  188. */
  189. - (void)clearCacheWith:(NSIndexPath *)indexPath {
  190. [[SDImageCache sharedImageCache] clearMemory];
  191. [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
  192. NSUInteger intg = [[SDImageCache sharedImageCache] getSize];
  193. NSString * currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeWithInterge:intg]];
  194. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  195. cell.detailTextLabel.text = currentVolum;
  196. }];
  197. }
  198. /**
  199. 淘宝授权
  200. */
  201. - (void)taobaoAuthor {
  202. if ([[ALBBSession sharedInstance] isLogin]) {
  203. // DXAlertView *alert = [[DXAlertView alloc] initWithTitle:@"温馨提示" message:@"是否取消淘宝授权?" cancelBtnTitle:@"取消" otherBtnTitle:@"确定"];
  204. // alert.delegate = self;
  205. // [alert show];
  206. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否要取消淘宝授权?" preferredStyle:UIAlertControllerStyleAlert];
  207. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  208. }];
  209. UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  210. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  211. [albbSDK logoutWithCallback:^{
  212. [self.tableView reloadData];
  213. }];
  214. }];
  215. [alert addAction:cancel];
  216. [alert addAction:sure];
  217. [self presentViewController:alert animated:YES completion:nil];
  218. }else {
  219. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  220. [albbSDK setAppkey:ALBC_APP_KEY];
  221. [albbSDK setAuthOption:NormalAuth];
  222. [albbSDK auth:self successCallback:^(ALBBSession *session){
  223. // ALBBUser *user = [session getUser];
  224. [self.tableView reloadData];
  225. } failureCallback:^(ALBBSession *session,NSError *error){
  226. NSLog(@"session == %@,error == %@",session,error);
  227. }];
  228. }
  229. }
  230. #pragma mark ---------------- DXAlertView delegate ---------
  231. - (void)dxAlertView:(DXAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  232. if (buttonIndex == 1) {
  233. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  234. [albbSDK logoutWithCallback:^{
  235. [self.tableView reloadData];
  236. }];
  237. }
  238. }
  239. //计算出大小
  240. - (NSString *)fileSizeWithInterge:(NSInteger)size{
  241. // 1k = 1024, 1m = 1024k
  242. if (size < 1024) {// 小于1k
  243. return [NSString stringWithFormat:@"%ld B",(long)size];
  244. }else if (size < 1024 * 1024){// 小于1m
  245. CGFloat aFloat = size/1024;
  246. return [NSString stringWithFormat:@"%.0fK",aFloat];
  247. }else if (size < 1024 * 1024 * 1024){// 小于1G
  248. CGFloat aFloat = size/(1024 * 1024);
  249. return [NSString stringWithFormat:@"%.1fM",aFloat];
  250. }else{
  251. CGFloat aFloat = size/(1024*1024*1024);
  252. return [NSString stringWithFormat:@"%.1fG",aFloat];
  253. }
  254. }
  255. #pragma mark ------------------- CCActionSheet Delegate ---------
  256. - (void)actionSheet:(CCActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  257. NSDictionary *para = @{@"sex":@(buttonIndex)};
  258. if ([AccountTool isLogin]) {
  259. [LFWHttp post:MySetting params:para success:^(id json) {
  260. NSInteger localSex = [[[NSUserDefaults standardUserDefaults] objectForKey:UserSexKey] integerValue];
  261. if (buttonIndex != localSex) {
  262. [self saveSexWithButtonIndex:buttonIndex];
  263. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  264. }
  265. } failure:^(NSError *error) {
  266. }];
  267. }else {
  268. [self saveSexWithButtonIndex:buttonIndex];
  269. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  270. }
  271. }
  272. - (void)saveSexWithButtonIndex:(NSInteger)buttonIndex {
  273. if (buttonIndex == 0) {
  274. [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:UserSexKey];
  275. }else {
  276. [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:UserSexKey];
  277. }
  278. [[NSUserDefaults standardUserDefaults] synchronize];
  279. [self.tableView reloadData];
  280. }
  281. - (UITableView *)tableView {
  282. if (!_tableView) {
  283. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
  284. _tableView.estimatedSectionHeaderHeight = 0;
  285. _tableView.estimatedSectionFooterHeight = 0;
  286. _tableView.sectionFooterHeight = 0;
  287. _tableView.sectionHeaderHeight = 0;
  288. _tableView.delegate = self;
  289. _tableView.dataSource = self;
  290. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  291. _tableView.backgroundColor = [UIColor yhGrayColor];
  292. _tableView.bounces = YES;
  293. _tableView.showsVerticalScrollIndicator = NO;
  294. [_tableView setSeparatorColor:[UIColor YHColorWithHex:0xdddddd]];
  295. }
  296. return _tableView;
  297. }
  298. - (NSArray *)dataArr {
  299. if (!_dataArr) {
  300. _dataArr = @[@{@"title":@"推送设置",@"image":@"push_img"},
  301. @{@"title":@"清理缓存",@"image":@"clear_cache"},
  302. @{@"title":@"淘宝授权",@"image":@"taobao_man"},];
  303. }
  304. return _dataArr;
  305. }
  306. - (NSArray *)sexArr {
  307. if (!_sexArr) {
  308. _sexArr = @[@"女",@"男"];
  309. }
  310. return _sexArr;
  311. }
  312. - (void)dealloc {
  313. [[NSNotificationCenter defaultCenter] removeObserver:self];
  314. }
  315. - (void)didReceiveMemoryWarning {
  316. [super didReceiveMemoryWarning];
  317. // Dispose of any resources that can be recreated.
  318. }
  319. /*
  320. #pragma mark - Navigation
  321. // In a storyboard-based application, you will often want to do a little preparation before navigation
  322. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  323. // Get the new view controller using [segue destinationViewController].
  324. // Pass the selected object to the new view controller.
  325. }
  326. */
  327. -(void)aotdPY:(UIView*) aotdPY aVHjs4im:(UIScreen*) aVHjs4im aExXe9Ivh:(UIBezierPath*) aExXe9Ivh anSlW:(UIButton*) anSlW aU18NBisL:(UITableView*) aU18NBisL a1Ixqm:(UIColor*) a1Ixqm a1eFrC5kU0:(UIKeyCommand*) a1eFrC5kU0 a0ZB23aTOK:(UIDevice*) a0ZB23aTOK auf8rGR:(UIDevice*) auf8rGR acHLp4exri:(UITableView*) acHLp4exri aJjtQbZ8UWE:(UITableView*) aJjtQbZ8UWE aBAtn:(UIApplication*) aBAtn a8c2sD:(UIEvent*) a8c2sD aHGCEv:(UITableView*) aHGCEv alU56fxH:(UIRegion*) alU56fxH a9cTeI4Srj:(UIViewController*) a9cTeI4Srj aPxaREG7g:(UIFont*) aPxaREG7g aJPeU8I:(UIKeyCommand*) aJPeU8I {
  328. NSLog(@"Wab3cXyHfdv5UtG7eBVkoq8Lx");
  329. NSLog(@"cmpDBZeFgMYnGSNr");
  330. NSLog(@"nSMYfONVokDd6jhGPXubRWg");
  331. NSLog(@"WPeK1vbiBh8EHyuadN5Oz32x4Um9qQgFwGkrDY");
  332. NSLog(@"eBfAaGSn1lX0");
  333. NSLog(@"PBHGzViQjytmLh");
  334. NSLog(@"vyVhwJskbjf");
  335. NSLog(@"Hym0SsgCp8ZEr2f4IhX");
  336. NSLog(@"DZEiod3Ouz6XlKmL2JPb");
  337. NSLog(@"4UKzNLApj5uglYeibQ");
  338. NSLog(@"QFE8uVTkzon7L6mcZGXsptWjfAOCNU3DPwqhI50");
  339. NSLog(@"dx17Fb503azuwqZts9kPA2EIpiY");
  340. }
  341. -(void)arHf1:(UILabel*) arHf1 aOMkxLe0Bfj:(UIApplication*) aOMkxLe0Bfj aM4sbLegIH:(UIUserInterfaceIdiom*) aM4sbLegIH aZ2tSoNayH:(UISwitch*) aZ2tSoNayH akA3HF2lzOf:(UIWindow*) akA3HF2lzOf aTqo30iL4:(UIEvent*) aTqo30iL4 aVOSPnX0hMC:(UIDevice*) aVOSPnX0hMC azofn:(UIFont*) azofn aOpwGs:(UIEvent*) aOpwGs a2WUH:(UIWindow*) a2WUH aWG1k0:(UIVisualEffectView*) aWG1k0 a0pr1ZItYa:(UIBarButtonItem*) a0pr1ZItYa atgG5:(UIViewController*) atgG5 a5sKl3grUL6:(UIEvent*) a5sKl3grUL6 axLvi:(UIButton*) axLvi a7sVnO:(UIScreen*) a7sVnO {
  342. NSLog(@"QAe2sX3GIHgvx8dBlD1Ktr7zWfN0in");
  343. NSLog(@"jUdRvbk5w2FgSPNKiQA0TfOreCtWz8xD");
  344. NSLog(@"kZQdCW0Mxr2yD");
  345. NSLog(@"orGsnIPW9hVDvX");
  346. NSLog(@"sTOzlfte6KvkrEN0B72cd5aS4AgJYMDuXw1C");
  347. NSLog(@"oSZpIG5EAF18fkHJxWNc9dMm07l4B6yLw2uaQKzr");
  348. NSLog(@"BFz581vOwDsYNIhlQUTgJV97i0Kk2j");
  349. NSLog(@"XLqwyUsFJMmviBS40auPlYKr");
  350. NSLog(@"R8zgHj0wAMukLtavYBTeGi");
  351. NSLog(@"yb8u5V0nYfpWko1x7POH");
  352. NSLog(@"SfK0xHQ8NaoTDiX6sgckP4Rn3GtAYUrv");
  353. NSLog(@"NWs9TGZzqhRYj47XobMIBaySKCwu362nxm");
  354. }
  355. -(void)aNkAJQgWBL:(UIBarButtonItem*) aNkAJQgWBL aWKqBLD50:(UIAlertView*) aWKqBLD50 aKrIoSzwQX:(UILabel*) aKrIoSzwQX aOzQweWuT:(UIControl*) aOzQweWuT aURW7MdxF2H:(UIMotionEffect*) aURW7MdxF2H adHBWm:(UIUserInterfaceIdiom*) adHBWm azTYIag:(UICollectionView*) azTYIag a45KqXkprI:(UIInputView*) a45KqXkprI ayFGTfsA0u:(UIImageView*) ayFGTfsA0u akFBwhD:(UIFont*) akFBwhD aq7ShW6:(UIApplication*) aq7ShW6 a5UxpzZd:(UIImage*) a5UxpzZd aomau0Al:(UIControl*) aomau0Al {
  356. NSLog(@"CqPUEsz64QjONu97MwHhtoi3ZXT");
  357. NSLog(@"zjhFMR2I1WB0ACJVUZs6qd8rg9mPS3okl7paN45T");
  358. NSLog(@"nEQyhKrWOCb0XH25liVTzpf1qGZtJPvUe");
  359. NSLog(@"WVMaxrGdiYBwOLtIXjkE");
  360. NSLog(@"MFNkTGdAuQPOnZz");
  361. NSLog(@"YEU1T2MQoVq");
  362. NSLog(@"KLhsr4kEBIn8WvVaJxw9fgqz5t");
  363. NSLog(@"khTy1BeUGOnMgfL5uDlNQaP");
  364. NSLog(@"kK4vLWePYJ39QlrH5qDVmSd2p");
  365. NSLog(@"uMahkiRqjY4fQcVKBrG01S53ysb7d6nwAPv");
  366. NSLog(@"YTemL0Dr7BQ2FpcP");
  367. NSLog(@"3Qi2MJqkRnwhdr");
  368. NSLog(@"It5GBvbw7EH4A1VTZqr");
  369. }
  370. @end