SceneDelegate.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // SceneDelegate.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/14.
  6. //
  7. #import <ComPDFKit/ComPDFKit.h>
  8. #import "SceneDelegate.h"
  9. #import "PDFListController.h"
  10. #import "PDFModel.h"
  11. @interface SceneDelegate ()
  12. @end
  13. @implementation SceneDelegate
  14. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
  15. // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
  16. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
  17. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
  18. [self setWindow:[[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene]];
  19. [self.window setBackgroundColor:[UIColor whiteColor]];
  20. [self.window makeKeyAndVisible];
  21. NSFileManager *fileManager = [NSFileManager defaultManager];
  22. NSURL *sampleURL = [NSBundle.mainBundle.resourceURL URLByAppendingPathComponent:@"Sample"];
  23. NSString *docsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
  24. NSArray *fileNames = [NSArray arrayWithObjects:@"3.pdf", nil];
  25. for (int i = 0; i < fileNames.count; i++) {
  26. NSURL *tBFilePath = [sampleURL URLByAppendingPathComponent:[fileNames objectAtIndex:i]];
  27. NSURL *tDFilePath = [NSURL fileURLWithPath:[docsFolder stringByAppendingPathComponent:[fileNames objectAtIndex:i]]];
  28. if (![fileManager fileExistsAtPath:tDFilePath.path]) {
  29. if ([fileManager fileExistsAtPath:tBFilePath.path]) {
  30. [fileManager copyItemAtURL:tBFilePath toURL:tDFilePath error:nil];
  31. }
  32. }
  33. }
  34. PDFModel *model = [[PDFModel alloc] init];
  35. model.filePath = docsFolder;
  36. NSLog(@"%@",model.filePath);
  37. PDFListController *pdfController = [[PDFListController alloc] initWithModel:model];
  38. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:pdfController];
  39. pdfController.navigationItem.title = @"Documents";
  40. [self.window setRootViewController:navigationController];
  41. }
  42. - (void)sceneDidDisconnect:(UIScene *)scene {
  43. // Called as the scene is being released by the system.
  44. // This occurs shortly after the scene enters the background, or when its session is discarded.
  45. // Release any resources associated with this scene that can be re-created the next time the scene connects.
  46. // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
  47. }
  48. - (void)sceneDidBecomeActive:(UIScene *)scene {
  49. // Called when the scene has moved from an inactive state to an active state.
  50. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
  51. }
  52. - (void)sceneWillResignActive:(UIScene *)scene {
  53. // Called when the scene will move from an active state to an inactive state.
  54. // This may occur due to temporary interruptions (ex. an incoming phone call).
  55. }
  56. - (void)sceneWillEnterForeground:(UIScene *)scene {
  57. // Called as the scene transitions from the background to the foreground.
  58. // Use this method to undo the changes made on entering the background.
  59. }
  60. - (void)sceneDidEnterBackground:(UIScene *)scene {
  61. // Called as the scene transitions from the foreground to the background.
  62. // Use this method to save data, release shared resources, and store enough scene-specific state information
  63. // to restore the scene back to its current state.
  64. }
  65. @end