AppDelegate.m 4.3 KB

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