CPDFViewBaseController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. //
  2. // CPDFViewBaseController.m
  3. // compdfkit-tools
  4. //
  5. // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFViewBaseController.h"
  13. #import "CDocumentPasswordViewController.h"
  14. #import <ComPDFKit/ComPDFKit.h>
  15. #import <compdfkit_tools/compdfkit_tools.h>
  16. @interface CPDFViewBaseController ()<UISearchBarDelegate,CPDFViewDelegate,CPDFListViewDelegate, CSearchToolbarDelegate, CPDFDisplayViewDelegate, CPDFBOTAViewControllerDelegate,CPDFSearchResultsDelegate, CPDFThumbnailViewControllerDelegate,CPDFPopMenuViewDelegate,UIDocumentPickerDelegate,CPDFPopMenuDelegate,CDocumentPasswordViewControllerDelegate>
  17. @property(nonatomic, strong) NSString *filePath;
  18. @property(nonatomic, strong) CPDFListView *pdfListView;
  19. @property(nonatomic, strong) CNavigationRightView *rightView;
  20. @property(nonatomic, strong) CSearchToolbar *searchToolbar;
  21. @property(nonatomic, strong) CActivityIndicatorView *loadingView;
  22. @property(nonatomic, strong) CPDFPopMenu *popMenu;
  23. @property(nonatomic, strong) UIBarButtonItem * leftBarButtonItem;
  24. @property(nonatomic, strong) NSString *password;
  25. @end
  26. @implementation CPDFViewBaseController
  27. #pragma mark - Initializers
  28. - (instancetype)initWithFilePath:(NSString *)filePath password:(nullable NSString *)password{
  29. if(self = [super init]) {
  30. self.filePath = filePath;
  31. self.password = password;
  32. }
  33. return self;
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
  38. [self initWitPDFListView];
  39. [self initWitNavigation];
  40. [self initWitNavigationTitle];
  41. [self initWithSearchTool];
  42. [self reloadDocumentWithFilePath:self.filePath password:self.password completion:^(BOOL result) {
  43. }];
  44. }
  45. #pragma mark - Private method
  46. -(void)updatePDFViewDocumentView {
  47. UIScrollView * documentView = [self.pdfListView documentView];
  48. if (CPDFDisplayDirectionVertical == [CPDFKitConfig sharedInstance].displayDirection) {
  49. if (self.pdfListView.currentPageIndex != 0) {
  50. if (@available(iOS 11.0, *)) {
  51. documentView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  52. } else {
  53. self.automaticallyAdjustsScrollViewInsets = NO;
  54. }
  55. } else {
  56. if (@available(iOS 11.0, *)) {
  57. documentView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  58. } else {
  59. self.automaticallyAdjustsScrollViewInsets = YES;
  60. }
  61. }
  62. } else {
  63. if (@available(iOS 11.0, *)) {
  64. documentView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  65. } else {
  66. self.automaticallyAdjustsScrollViewInsets = NO;
  67. }
  68. }
  69. }
  70. - (void)initWitPDFListView {
  71. self.pdfListView = [[CPDFListView alloc] initWithFrame:self.view.bounds];
  72. self.pdfListView.performDelegate = self;
  73. self.pdfListView.delegate = self;
  74. self.pdfListView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  75. [self.view addSubview:self.pdfListView];
  76. }
  77. - (void)initWitNavigation {
  78. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"CPDFThunbnailImageEnter" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(buttonItemClicked_thumbnail:)];
  79. self.navigationItem.leftBarButtonItem = leftItem;
  80. self.leftBarButtonItem = leftItem;
  81. __block typeof(self) blockSelf = self;
  82. self.rightView = [[CNavigationRightView alloc] initWithDefaultItemsClickBack:^(NSUInteger tag) {
  83. switch (tag) {
  84. case CNavigationRightTypeSearch:
  85. [blockSelf navigationRightItemSearch];
  86. break;
  87. case CNavigationRightTypeBota:
  88. [blockSelf navigationRightItemBota];
  89. break;
  90. default:
  91. case CNavigationRightTypeMore:
  92. [blockSelf navigationRightItemMore];
  93. break;
  94. }
  95. }];
  96. }
  97. - (void)initWithSearchTool {
  98. self.searchToolbar = [[CSearchToolbar alloc] initWithPDFView:self.pdfListView];
  99. self.searchToolbar.delegate = self;
  100. }
  101. - (void)enterPDFSetting {
  102. [self.popMenu hideMenu];
  103. CPDFDisplayViewController *displayVc = [[CPDFDisplayViewController alloc] initWithPDFView:self.pdfListView];
  104. displayVc.delegate = self;
  105. AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  106. presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:displayVc presentingViewController:self];
  107. displayVc.transitioningDelegate = presentationController;
  108. [self presentViewController:displayVc animated:YES completion:nil];
  109. }
  110. - (void)enterPDFInfo {
  111. [self.popMenu hideMenu];
  112. CPDFInfoViewController * infoVc = [[CPDFInfoViewController alloc] initWithPDFView:self.pdfListView];
  113. AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  114. presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:infoVc presentingViewController:self];
  115. infoVc.transitioningDelegate = presentationController;
  116. [self presentViewController:infoVc animated:YES completion:nil];
  117. }
  118. - (void)enterPDFShare {
  119. [self.popMenu hideMenu];
  120. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  121. if(self.pdfListView.document.isModified) {
  122. [self.pdfListView.document writeToURL:self.pdfListView.document.documentURL];
  123. }
  124. dispatch_async(dispatch_get_main_queue(), ^{
  125. [self shareAction];
  126. });
  127. });
  128. }
  129. - (void)enterPDFAddFile {
  130. [self.popMenu hideMenu];
  131. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  132. if(self.pdfListView.document.isModified) {
  133. [self.pdfListView.document writeToURL:self.pdfListView.document.documentURL];
  134. }
  135. dispatch_async(dispatch_get_main_queue(), ^{
  136. NSArray *documentTypes = @[@"com.adobe.pdf"];
  137. UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];
  138. documentPickerViewController.delegate = self;
  139. [self presentViewController:documentPickerViewController animated:YES completion:nil];
  140. });
  141. });
  142. }
  143. #pragma mark - Public method
  144. - (void)initWitNavigationTitle {
  145. CNavigationBarTitleButton * navTitleButton = [[CNavigationBarTitleButton alloc] init];
  146. self.titleButton = navTitleButton;
  147. self.navigationTitle = NSLocalizedString(@"Viewer", nil);
  148. [navTitleButton setTitle:self.navigationTitle forState:UIControlStateNormal];
  149. [navTitleButton setTitleColor:[CPDFColorUtils CAnyReverseBackgooundColor] forState:UIControlStateNormal];
  150. self.titleButton.frame = CGRectMake(0, 0, 100, 30);
  151. self.navigationItem.titleView = self.titleButton;
  152. }
  153. - (void)reloadDocumentWithFilePath:(NSString *)filePath password:(nullable NSString *)password completion:(void (^)(BOOL result))completion {
  154. [self.navigationController.view setUserInteractionEnabled:NO];
  155. if (![self.loadingView superview]) {
  156. [self.view addSubview:self.loadingView];
  157. }
  158. [self.loadingView startAnimating];
  159. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  160. NSURL *url = [NSURL fileURLWithPath:filePath];
  161. CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
  162. if([document isLocked]) {
  163. [document unlockWithPassword:password];
  164. }
  165. dispatch_async(dispatch_get_main_queue(), ^{
  166. [self.navigationController.view setUserInteractionEnabled:YES];
  167. [self.loadingView stopAnimating];
  168. [self.loadingView removeFromSuperview];
  169. if (document.error && document.error.code != CPDFDocumentPasswordError) {
  170. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  171. [self.navigationController popViewControllerAnimated:YES];
  172. }];
  173. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
  174. message:NSLocalizedString(@"Sorry PDF Reader Can't open this pdf file!", nil)
  175. preferredStyle:UIAlertControllerStyleAlert];
  176. [alert addAction:okAction];
  177. if (completion) {
  178. completion(NO);
  179. }
  180. } else {
  181. self.pdfListView.document = document;
  182. if (completion) {
  183. completion(YES);
  184. }
  185. }
  186. });
  187. });
  188. }
  189. - (void)setTitleRefresh {
  190. }
  191. - (void)selectDocumentRefresh {
  192. }
  193. #pragma mark - Action
  194. - (void)navigationRightItemSearch {
  195. [self.searchToolbar showInView:self.navigationController.navigationBar];
  196. self.navigationTitle = @"";
  197. self.titleButton.hidden = YES;
  198. self.navigationItem.rightBarButtonItem = nil;
  199. self.navigationItem.leftBarButtonItem = nil;
  200. }
  201. - (void)navigationRightItemBota {
  202. CPDFBOTAViewController *botaViewController = [[CPDFBOTAViewController alloc] initWithPDFView:self.pdfListView];
  203. botaViewController.delegate = self;
  204. AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  205. presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:botaViewController presentingViewController:self];
  206. botaViewController.transitioningDelegate = presentationController;
  207. [self presentViewController:botaViewController animated:YES completion:nil];
  208. }
  209. - (void)navigationRightItemMore {
  210. CPDFPopMenuView * menuView = [[CPDFPopMenuView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
  211. menuView.delegate = self;
  212. self.popMenu = [CPDFPopMenu popMenuWithContentView:menuView];
  213. self.popMenu.dimCoverLayer = YES;
  214. self.popMenu.delegate = self;
  215. if (@available(iOS 11.0, *)) {
  216. [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
  217. } else {
  218. // Fallback on earlier versions
  219. [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 200)];
  220. }
  221. }
  222. - (void)buttonItemClicked_thumbnail:(id)sender {
  223. CPDFThumbnailViewController *thumbnailViewController = [[CPDFThumbnailViewController alloc] initWithPDFView:self.pdfListView];
  224. thumbnailViewController.delegate = self;
  225. AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  226. presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:thumbnailViewController presentingViewController:self];
  227. thumbnailViewController.transitioningDelegate = presentationController;
  228. [self presentViewController:thumbnailViewController animated:YES completion:nil];
  229. }
  230. #pragma mark - CPDFViewDelegate
  231. - (void)PDFViewDocumentDidLoaded:(CPDFView *)pdfView {
  232. UIBarButtonItem* rightItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightView];
  233. self.navigationItem.rightBarButtonItem = rightItem;
  234. [self updatePDFViewDocumentView];
  235. }
  236. - (void)PDFViewCurrentPageDidChanged:(CPDFListView *)pdfView {
  237. [self updatePDFViewDocumentView];
  238. }
  239. - (void)PDFViewPerformURL:(CPDFView *)pdfView withContent:(NSString *)content {
  240. if (content) {
  241. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:content]];
  242. } else {
  243. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
  244. style:UIAlertActionStyleCancel
  245. handler:nil];
  246. UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Error", nil)
  247. message:NSLocalizedString(@"The hyperlink is invalid.", nil)
  248. preferredStyle:UIAlertControllerStyleAlert];
  249. [alert addAction:cancelAction];
  250. [self presentViewController:alert animated:YES completion:nil];
  251. }
  252. }
  253. - (void)PDFViewPerformReset:(CPDFView *)pdfView {
  254. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Yes", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  255. [self.pdfListView.document resetForm];
  256. [self.pdfListView setNeedsDisplayForVisiblePages];
  257. }];
  258. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"No", nil) style:UIAlertActionStyleCancel handler:nil];
  259. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
  260. message:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to reset the form?", nil)]
  261. preferredStyle:UIAlertControllerStyleAlert];
  262. [alert addAction:okAction];
  263. [alert addAction:cancelAction];
  264. [self presentViewController:alert animated:YES completion:nil];
  265. }
  266. - (void)PDFViewPerformPrint:(CPDFView *)pdfView {
  267. NSLog(@"Print");
  268. }
  269. #pragma mark - CSearchToolbarDelegate
  270. - (void)searchToolbar:(CSearchToolbar *)searchToolbar onSearchQueryResults:(NSArray *)results {
  271. if ([results count] < 1) {
  272. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
  273. style:UIAlertActionStyleCancel
  274. handler:nil];
  275. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
  276. message:NSLocalizedString(@"your have‘t search result", nil)
  277. preferredStyle:UIAlertControllerStyleAlert];
  278. [alert addAction:cancelAction];
  279. [self presentViewController:alert animated:YES completion:nil];
  280. return;
  281. }
  282. CPDFSearchResultsViewController* searchResultController = [[CPDFSearchResultsViewController alloc] initWithResultArray:results keyword:searchToolbar.searchKeyString document:self.pdfListView.document];
  283. searchResultController.delegate = self;
  284. AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  285. presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:searchResultController presentingViewController:self];
  286. searchResultController.transitioningDelegate = presentationController;
  287. [self presentViewController:searchResultController animated:YES completion:nil];
  288. }
  289. - (void)searchToolbarOnExitSearch:(CSearchToolbar *)searchToolbar {
  290. if([searchToolbar superview]) {
  291. [searchToolbar removeFromSuperview];
  292. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightView];
  293. self.navigationItem.rightBarButtonItem = rightItem;
  294. self.title = self.navigationTitle;
  295. self.navigationItem.leftBarButtonItem = self.leftBarButtonItem;
  296. }
  297. self.navigationTitle = NSLocalizedString(@"Viewer",nil);
  298. self.titleButton.hidden = NO;
  299. }
  300. #pragma mark - CPDFDisplayViewDelegate
  301. - (void)displayViewControllerDismiss:(CPDFDisplayViewController *)displayViewController {
  302. [self.navigationController popToRootViewControllerAnimated:YES];
  303. }
  304. #pragma mark - CPDFBOTAViewControllerDelegate
  305. - (void)botaViewControllerDismiss:(CPDFBOTAViewController *)botaViewController {
  306. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  307. }
  308. #pragma mark - CPDFSearchResultsDelegate
  309. - (void)searchResultsView:(CPDFSearchResultsViewController *)resultVC forSelection:(CPDFSelection *)selection indexPath:(NSIndexPath *)indexPath {
  310. NSInteger pageIndex = [self.pdfListView.document indexForPage:selection.page];
  311. [self.pdfListView goToPageIndex:pageIndex animated:NO];
  312. [self.pdfListView setHighlightedSelection:selection animated:YES];
  313. }
  314. - (void)searchResultsViewControllerDismiss:(CPDFSearchResultsViewController *)searchResultsViewController {
  315. [self.navigationController popViewControllerAnimated:YES];
  316. }
  317. #pragma mark - CPDFPopMenuDelegate
  318. - (void)menuDidClosedIn:(CPDFPopMenu *)menu isClosed:(BOOL)isClosed {
  319. }
  320. #pragma mark - CPDFThumbnailViewControllerDelegate
  321. - (void)thumbnailViewController:(CPDFThumbnailViewController *)thumbnailViewController pageIndex:(NSInteger)pageIndex {
  322. [self.pdfListView goToPageIndex:pageIndex animated:NO];
  323. [self.navigationController popViewControllerAnimated:YES];
  324. }
  325. #pragma mark - CPDFMenuViewdelegate
  326. - (void)menuDidClickAtView:(CPDFPopMenuView *)view clickType:(CPDFPopMenuViewType)viewType {
  327. switch (viewType) {
  328. case CPDFPopMenuViewTypeSetting: {
  329. [self enterPDFSetting];
  330. }
  331. break;
  332. case CPDFPopMenuViewTypeInfo:{
  333. [self enterPDFInfo];
  334. }
  335. break;
  336. case CPDFPopMenuViewTypeShare: {
  337. [self enterPDFShare];
  338. }
  339. break;
  340. case CPDFPopMenuViewTypeAddFile: {
  341. [self enterPDFAddFile];
  342. }
  343. default:
  344. break;
  345. }
  346. }
  347. - (void)shareAction {
  348. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[self.pdfListView.document.documentURL] applicationActivities:nil];
  349. activityVC.definesPresentationContext = YES;
  350. if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
  351. activityVC.popoverPresentationController.sourceView = self.rightView;
  352. activityVC.popoverPresentationController.sourceRect = CGRectMake(self.rightView.bounds.origin.x + (self.rightView.bounds.size.width)/3*2 + 10, CGRectGetMaxY(self.rightView.bounds), 1, 1);
  353. }
  354. [self presentViewController:activityVC animated:YES completion:nil];
  355. activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
  356. if (completed) {
  357. NSLog(@"Success!");
  358. } else {
  359. NSLog(@"Failed Or Canceled!");
  360. }
  361. };
  362. }
  363. #pragma mark - UIDocumentPickerDelegate
  364. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
  365. BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
  366. if(fileUrlAuthozied){
  367. NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
  368. NSError *error;
  369. [fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
  370. NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@", @"Documents",@"Files"];
  371. if (![[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
  372. [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:documentFolder] withIntermediateDirectories:YES attributes:nil error:nil];
  373. NSString * documentPath = [documentFolder stringByAppendingPathComponent:[newURL lastPathComponent]];
  374. if (![[NSFileManager defaultManager] fileExistsAtPath:documentPath]) {
  375. [[NSFileManager defaultManager] copyItemAtPath:newURL.path toPath:documentPath error:NULL];
  376. }
  377. NSURL *url = [NSURL fileURLWithPath:documentPath];
  378. CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
  379. self.filePath = documentPath;
  380. if (document.error && document.error.code != CPDFDocumentPasswordError) {
  381. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  382. }];
  383. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
  384. message:NSLocalizedString(@"Sorry PDF Reader Can't open this pdf file!", nil)
  385. preferredStyle:UIAlertControllerStyleAlert];
  386. [alert addAction:okAction];
  387. UIViewController *tRootViewControl = [UIApplication sharedApplication].keyWindow.rootViewController;
  388. if ([tRootViewControl presentedViewController]) {
  389. tRootViewControl = [tRootViewControl presentedViewController];
  390. }
  391. [tRootViewControl presentViewController:alert animated:YES completion:nil];
  392. } else {
  393. if([document isLocked]) {
  394. CDocumentPasswordViewController *documentPasswordVC = [[CDocumentPasswordViewController alloc] initWithDocument:document];
  395. documentPasswordVC.delegate = self;
  396. documentPasswordVC.modalPresentationStyle = UIModalPresentationFullScreen;
  397. UIViewController *tRootViewControl = [UIApplication sharedApplication].keyWindow.rootViewController;
  398. if ([tRootViewControl presentedViewController]) {
  399. tRootViewControl = [tRootViewControl presentedViewController];
  400. }
  401. [tRootViewControl presentViewController:documentPasswordVC animated:YES completion:nil];
  402. } else {
  403. self.pdfListView.document = document;
  404. [self selectDocumentRefresh];
  405. }
  406. }
  407. }];
  408. [urls.firstObject stopAccessingSecurityScopedResource];
  409. }
  410. [self setTitleRefresh];
  411. }
  412. - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
  413. [self setTitleRefresh];
  414. }
  415. #pragma mark - CDocumentPasswordViewControllerDelegate
  416. - (void)documentPasswordViewControllerOpen:(CDocumentPasswordViewController *)documentPasswordViewController document:(nonnull CPDFDocument *)document {
  417. self.pdfListView.document = document;
  418. [self selectDocumentRefresh];
  419. }
  420. @end