AppDelegate.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // AppDelegate.m
  3. // ComPDFKit_Samples
  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 "XMLReader.h"
  15. #import "CSamplesFuctionViewController.h"
  16. static AppDelegate *appDelegate = NULL;
  17. @interface AppDelegate ()
  18. @property (nonatomic, strong) UIWindow *window;
  19. @end
  20. @implementation AppDelegate
  21. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  22. // Override point for customization after application launch.
  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 *filePathTest1 = [[NSBundle mainBundle] pathForResource:@"Blank Page" ofType:@"pdf"];
  54. NSString *filePathTest2 = [[NSBundle mainBundle] pathForResource:@"PDF32000_2008" ofType:@"pdf"];
  55. NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@", @"Documents",@"Samples"];
  56. if (![[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
  57. [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:documentFolder] withIntermediateDirectories:YES attributes:nil error:nil];
  58. NSString * documentPathTest1 = [documentFolder stringByAppendingPathComponent:filePathTest1.lastPathComponent];
  59. if (![[NSFileManager defaultManager] fileExistsAtPath:documentPathTest1])
  60. [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:filePathTest1] toURL:[NSURL fileURLWithPath:documentPathTest1] error:nil];
  61. NSString * documentPathTest2 = [documentFolder stringByAppendingPathComponent:filePathTest2.lastPathComponent];
  62. if (![[NSFileManager defaultManager] fileExistsAtPath:documentPathTest2])
  63. [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:filePathTest2] toURL:[NSURL fileURLWithPath:documentPathTest2] error:nil];
  64. CSamplesFuctionViewController *viewVC = [[CSamplesFuctionViewController alloc] initWithFilePath:@[documentPathTest1, documentPathTest2] password:nil];
  65. UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:viewVC];
  66. self.window.rootViewController = navController;
  67. [self.window makeKeyAndVisible];
  68. }
  69. + (AppDelegate *)sharedAppDelegate {
  70. if (!appDelegate)
  71. appDelegate = [[AppDelegate alloc] init];
  72. return appDelegate;
  73. }
  74. #pragma mark - UISceneSession lifecycle
  75. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) {
  76. // Called when a new scene session is being created.
  77. // Use this method to select a configuration to create the new scene with.
  78. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  79. }
  80. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions API_AVAILABLE(ios(13.0)) {
  81. // Called when the user discards a scene session.
  82. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  83. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  84. }
  85. @end