HomeTestViewController.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // HomeTestViewController.m
  3. // smartRhino
  4. //
  5. // Created by taidi on 2019/12/9.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "HomeTestViewController.h"
  9. @interface HomeTestViewController ()<UIDocumentPickerDelegate>
  10. @end
  11. @implementation HomeTestViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. [self addButton:@"预览" withX:50 Withy:50 WithWidth:150 withHeight:50];
  15. [self addButton:@"三方列表" withX:50 Withy:150 WithWidth:150 withHeight:50];
  16. [self addButton:@"导入" withX:50 Withy:250 WithWidth:150 withHeight:50];
  17. [self addButton:@"导出" withX:50 Withy:350 WithWidth:150 withHeight:50];
  18. }
  19. - (void)addButton:(NSString*)string withX:(CGFloat)x Withy:(CGFloat)y WithWidth:(CGFloat)w withHeight:(CGFloat)h{
  20. UIButton *addButton = [[UIButton alloc]initWithFrame:CGRectMake(x, y, w, h)];
  21. [addButton setTitle:string forState:UIControlStateNormal];
  22. [addButton addTarget:self action:@selector(importFile) forControlEvents:UIControlEventTouchUpInside];
  23. [addButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
  24. [self.view addSubview:addButton];
  25. }
  26. /// 道出
  27. -(void)importFile2{
  28. NSURL *url = [[NSBundle mainBundle] URLForResource:@"App" withExtension:@"pdf"];
  29. UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithURL:url
  30. inMode:UIDocumentPickerModeExportToService];
  31. documentPicker.delegate = self;
  32. documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
  33. [self presentViewController:documentPicker animated:YES completion:nil];
  34. }
  35. -(void)importFile{
  36. UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc]
  37. initWithDocumentTypes:@[@"public.image",@"com.adobe.pdf"] inMode:UIDocumentPickerModeImport];
  38. documentPicker.delegate = self;
  39. documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
  40. [self presentViewController:documentPicker animated:YES completion:nil];
  41. }
  42. #pragma mark - UIDocumentPickerDelegate
  43. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
  44. if (controller.documentPickerMode == UIDocumentPickerModeImport) {
  45. NSString *alertMessage = [NSString stringWithFormat:@"Successfully imported %@", [[urls lastObject] lastPathComponent]];
  46. dispatch_async(dispatch_get_main_queue(), ^{
  47. UIAlertController *alertController = [UIAlertController
  48. alertControllerWithTitle:@"Import"
  49. message:alertMessage
  50. preferredStyle:UIAlertControllerStyleAlert];
  51. [alertController addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]];
  52. [self presentViewController:alertController animated:YES completion:nil];
  53. });
  54. }
  55. }
  56. @end