AppDelegate.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // AppDelegate.m
  3. // ComPDFKit
  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 "AppDelegate.h"
  13. #import <ComPDFKit/ComPDFKit.h>
  14. #import <compdfkit_tools/compdfkit_tools.h>
  15. #import "CPDFViewController.h"
  16. #import "XMLParseManager.h"
  17. static AppDelegate *appDelegate = NULL;
  18. @interface AppDelegate ()
  19. @property (nonatomic, strong) UIWindow *window;
  20. @property (nonatomic, strong) XMLParseManager *manager;
  21. @end
  22. @implementation AppDelegate
  23. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  24. // Override point for customization after application launch.
  25. NSString *path = [[NSBundle mainBundle]pathForResource:@"SDKLicense" ofType:@"xml"];
  26. NSURL *url = [NSURL fileURLWithPath:path];
  27. _manager = [[XMLParseManager alloc]init];
  28. [_manager parseXMLWithURL:url completion:^(BOOL SUC, XPDXMLElement *data,NSError *error) {
  29. if (SUC) {
  30. NSDictionary * attribute = data.attribute;
  31. NSString * key = attribute[@"key"];
  32. NSString * secret = attribute[@"secret"];
  33. [CPDFKit setLicenseKey:key secret:secret];
  34. if (@available(iOS 13.0, *)) {
  35. } else {
  36. UIWindow *windows = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  37. [self configWindow:windows];
  38. }
  39. }else{
  40. NSLog(@"error = %@",error);
  41. }
  42. }];
  43. return YES;
  44. }
  45. - (void)configWindow:(UIWindow *)window {
  46. self.window = window;
  47. self.window.backgroundColor = [UIColor whiteColor];
  48. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Quick Start Guide" ofType:@"pdf"];
  49. NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@", @"Documents",@"Samples"];
  50. if (![[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
  51. [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:documentFolder] withIntermediateDirectories:YES attributes:nil error:nil];
  52. NSString * documentPath = [documentFolder stringByAppendingPathComponent:filePath.lastPathComponent];
  53. if (![[NSFileManager defaultManager] fileExistsAtPath:documentPath])
  54. [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:filePath] toURL:[NSURL fileURLWithPath:documentPath] error:nil];
  55. CPDFViewController *pdfViewController = [[CPDFViewController alloc] initWithFilePath:documentPath password:nil];
  56. CNavigationController *navController = [[CNavigationController alloc]initWithRootViewController:pdfViewController];
  57. self.window.rootViewController = navController;
  58. [self.window makeKeyAndVisible];
  59. }
  60. + (AppDelegate *)sharedAppDelegate {
  61. if (!appDelegate)
  62. appDelegate = [[AppDelegate alloc] init];
  63. return appDelegate;
  64. }
  65. #pragma mark - UISceneSession lifecycle
  66. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
  67. // Called when a new scene session is being created.
  68. // Use this method to select a configuration to create the new scene with.
  69. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  70. }
  71. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
  72. // Called when the user discards a scene session.
  73. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  74. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  75. }
  76. @end