PrivacyPolicyVC.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // PrivacyPolicyVC.m
  3. // XWorld_General
  4. //
  5. // Created by SaturdayNight on 2018/5/4.
  6. // Copyright © 2018年 xiongmaitech. All rights reserved.
  7. //
  8. #import "PrivacyPolicyVC.h"
  9. #import <Masonry/Masonry.h>
  10. #import "Header.h"
  11. static NSString * const privacyURL = @"https://www.xmeye.net/page/privacy.jsp";
  12. @interface PrivacyPolicyVC ()
  13. @property (nonatomic,strong) UIWebView *webPrivacy;
  14. @end
  15. @implementation PrivacyPolicyVC
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.view.backgroundColor = [UIColor whiteColor];
  19. [self configNav];
  20. [self.view addSubview:self.webPrivacy];
  21. [self myLayout];
  22. }
  23. #pragma mark - EventAction
  24. -(void)backItemClicked
  25. {
  26. [self.navigationController popViewControllerAnimated:YES];
  27. }
  28. #pragma mark - 设置导航栏
  29. -(void)configNav
  30. {
  31. self.navigationItem.title = TS("Privacy_Policy");
  32. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"new_back.png"] style:UIBarButtonItemStyleDone target:self action:@selector(backItemClicked)];
  33. self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  34. self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
  35. }
  36. #pragma mark - Layout
  37. -(void)myLayout
  38. {
  39. [self.webPrivacy mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.equalTo(self.view);
  41. make.right.equalTo(self.view);
  42. make.top.equalTo(self.view);
  43. make.bottom.equalTo(self.view);
  44. }];
  45. }
  46. #pragma mark - LazyLoad
  47. -(UIWebView *)webPrivacy
  48. {
  49. if (!_webPrivacy) {
  50. _webPrivacy = [[UIWebView alloc] init];
  51. NSURL *url = [NSURL URLWithString:privacyURL];
  52. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  53. [_webPrivacy loadRequest:request];
  54. [self writeToCache];
  55. }
  56. return _webPrivacy;
  57. }
  58. - (void)writeToCache
  59. {
  60. NSString * htmlResponseStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:privacyURL] encoding:NSUTF8StringEncoding error:Nil];
  61. //创建文件管理器
  62. NSFileManager *fileManager = [[NSFileManager alloc] init];
  63. //获取document路径
  64. NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  65. [fileManager createDirectoryAtPath:[cachesPath stringByAppendingString:@"/Caches"] withIntermediateDirectories:YES attributes:nil error:nil];
  66. //写入路径
  67. NSString * path = [cachesPath stringByAppendingString:[NSString stringWithFormat:@"/Caches/%@.html",@"privacyCache"]];
  68. [htmlResponseStr writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
  69. }
  70. @end