QMChatRoomShowFileController.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // QMChatRoomShowFileController.m
  3. // IMSDK-OC
  4. //
  5. // Created by HCF on 16/8/15.
  6. // Copyright © 2016年 HCF. All rights reserved.
  7. //
  8. #import "QMChatRoomShowFileController.h"
  9. @interface QMChatRoomShowFileController ()
  10. @end
  11. @implementation QMChatRoomShowFileController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. self.view.backgroundColor = [UIColor whiteColor];
  15. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  16. button.frame = CGRectMake(10, 20, 60, 30);
  17. [button setTitle:NSLocalizedString(@"button.back", nil) forState:UIControlStateNormal];
  18. [button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  19. [self.view addSubview:button];
  20. UIWebView * webView = [[UIWebView alloc] init];
  21. webView.frame = CGRectMake(0, 64, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT-64);
  22. [webView scalesPageToFit];
  23. webView.backgroundColor = [UIColor whiteColor];
  24. [self.view addSubview:webView];
  25. NSString * filePath = [NSString stringWithFormat:@"%@/%@/%@",NSHomeDirectory(),@"Documents",self.filePath];
  26. // 中文路径要encode
  27. NSString * fileUrl = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  28. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:fileUrl]];
  29. [webView loadRequest:request];
  30. }
  31. - (void)backAction {
  32. [self dismissViewControllerAnimated:YES completion:nil];
  33. }
  34. - (void)didReceiveMemoryWarning {
  35. [super didReceiveMemoryWarning];
  36. // Dispose of any resources that can be recreated.
  37. }
  38. @end