123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //
- // AppDelegate.m
- // ContentEditor
- //
- // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- //
- // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- // This notice may not be removed from this file.
- //
- #import "AppDelegate.h"
- #import <ComPDFKit/ComPDFKit.h>
- #import <ComPDFKit_Tools/ComPDFKit_Tools.h>
- #import "CPDFViewController.h"
- #import "XMLReader.h"
- static AppDelegate *appDelegate = NULL;
- @interface AppDelegate ()
- @property (nonatomic, strong) UIWindow *window;
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-
- NSString *xmlFileString = [[NSBundle mainBundle] pathForResource:@"license_key_ios" ofType:@"xml"];
- NSData *xmlData = [NSData dataWithContentsOfFile:xmlFileString];
- NSError *error = nil;
-
- NSDictionary *result = [XMLReader dictionaryForXMLData:xmlData error:&error];
- if (error)
- NSLog(@"License key can not be empty.");
-
- if([result isKindOfClass:[NSDictionary class]]) {
- NSDictionary *license = [result objectForKey:@"license"];
- if([license isKindOfClass:[NSDictionary class]]) {
- NSDictionary * keysDic = license[@"key"];
- NSDictionary * secretDic = license[@"secret"];
-
- NSString * key = keysDic[@"text"];
- NSString * secret = secretDic[@"text"];
- [CPDFKit setLicenseKey:key secret:secret];
- } else {
- NSLog(@"License key can not be empty.");
- }
- } else {
- NSLog(@"License key can not be empty.");
- }
-
- if (@available(iOS 13.0, *)) {
-
- } else {
- UIWindow *windows = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- [self configWindow:windows];
- }
- return YES;
- }
- - (void)configWindow:(UIWindow *)window {
- self.window = window;
- self.window.backgroundColor = [UIColor whiteColor];
-
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"PDF32000_2008" ofType:@"pdf"];
- NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@", @"Documents",@"Samples"];
- if (![[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
- [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:documentFolder] withIntermediateDirectories:YES attributes:nil error:nil];
-
- NSString * documentPath = [documentFolder stringByAppendingPathComponent:filePath.lastPathComponent];
- if (![[NSFileManager defaultManager] fileExistsAtPath:documentPath])
- [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:filePath] toURL:[NSURL fileURLWithPath:documentPath] error:nil];
-
- CPDFViewController *pdfViewController = [[CPDFViewController alloc] initWithFilePath:documentPath password:nil];
- CNavigationController *navController = [[CNavigationController alloc]initWithRootViewController:pdfViewController];
- self.window.rootViewController = navController;
-
- [self.window makeKeyAndVisible];
- }
- + (AppDelegate *)sharedAppDelegate {
- if (!appDelegate)
- appDelegate = [[AppDelegate alloc] init];
-
- return appDelegate;
- }
- #pragma mark - UISceneSession lifecycle
- - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)){
- // Called when a new scene session is being created.
- // Use this method to select a configuration to create the new scene with.
- return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
- }
- - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions API_AVAILABLE(ios(13.0)){
- // Called when the user discards a scene session.
- // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
- // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
- }
- @end
|