AppDelegate.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // AppDelegate.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/16/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "ACNetwork.h"
  10. #import "TextUtils.h"
  11. #import "PDFUtils.h"
  12. #import "RAUtils.h"
  13. #import "AddExtDocumentViewController.h"
  14. //#import "AFHTTPSessionManager.h"
  15. @interface AppDelegate ()
  16. @end
  17. @implementation AppDelegate
  18. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  19. // Override point for customization after application launch.
  20. self.bEnable_Cache = true;
  21. [self function_test];
  22. return YES;
  23. }
  24. -(NSString*) filetype:(NSString*)filePath
  25. {
  26. NSString *suffix = [filePath pathExtension];
  27. if([suffix.lowercaseString isEqualToString:@"jpg"]||[suffix.lowercaseString isEqualToString:@"png"]||[suffix.lowercaseString isEqualToString:@"bmp"]||[suffix.lowercaseString isEqualToString:@"gif"])
  28. return @"image";
  29. else
  30. return @"file";
  31. }
  32. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options
  33. {
  34. NSLog(@"URL:%@, OPTIONS:%@",[url absoluteString],[RAUtils dict2string:options]);
  35. if(self.bLogin)
  36. {
  37. UINavigationController *rootVC = (UINavigationController *)application.keyWindow.rootViewController;
  38. UIViewController* presentVC=rootVC.presentedViewController;
  39. UIViewController* topvc= rootVC.topViewController;
  40. NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
  41. UIImage* img=[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
  42. item[@"type"]=[self filetype:url.absoluteString];
  43. item[@"url"]= [url path];
  44. item[@"file_name"] = [url.absoluteString lastPathComponent];
  45. AddExtDocumentViewController * addVC = [ [UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AddExtDocumentViewController"];
  46. addVC.is_present = true;
  47. addVC.doc_number = nil;
  48. addVC.arr_documents = [NSMutableArray arrayWithObjects:item, nil];
  49. // notesVC.docNotes = notes;
  50. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:addVC] ;
  51. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  52. [rootVC presentViewController:navi animated:YES completion:^{
  53. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  54. DebugLog(@"filter present.........");
  55. // self.btop = false;
  56. // <#code#>
  57. }];
  58. }
  59. else
  60. {
  61. }
  62. // [ pushViewController:addVC animated:false];
  63. // return YES;
  64. return YES;
  65. }
  66. -(void)function_test
  67. {
  68. return;
  69. printf("function test======================");
  70. // NSString* pdffile = [PDFUtils SavePDF:nil source:nil window_rect:CGRectMake(0, 0, 768, 960)];
  71. // [PDFUtils leak_test];
  72. // 获取路径
  73. NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
  74. NSString *saveDirectory=[paths objectAtIndex:0];
  75. NSString *saveFileName=[NSString stringWithFormat:@"%@.pdf",[[NSUUID UUID ] UUIDString] ] ;;
  76. NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
  77. const char *filename=[newFilePath UTF8String];
  78. NSLog(@"%@",newFilePath);
  79. //设置页面大小 Letter纸
  80. CFStringRef path;
  81. CFURLRef url;
  82. path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
  83. url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
  84. CFRelease(path);
  85. // CGPDFCONTEXTCREATE
  86. CGContextRef pdfContext;
  87. CGRect docsize = CGRectMake(0, 0, 612, 1008);
  88. CFMutableDictionaryRef myDictionary = NULL;
  89. myDictionary= CFDictionaryCreateMutable(NULL,
  90. 0,
  91. NULL,
  92. NULL);
  93. CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("usai2010"));
  94. CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanTrue);
  95. CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
  96. pdfContext=CGPDFContextCreateWithURL(url, &docsize,myDictionary);
  97. CFRelease(myDictionary);
  98. CFRelease(url);
  99. CGContextBeginPage(pdfContext, &docsize);
  100. // cgpdfpage
  101. CGContextEndPage(pdfContext);
  102. CGPDFContextClose(pdfContext);
  103. CGContextRelease(pdfContext);
  104. return ;
  105. }
  106. - (void)applicationWillResignActive:(UIApplication *)application {
  107. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  108. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  109. }
  110. - (void)applicationDidEnterBackground:(UIApplication *)application {
  111. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  112. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  113. }
  114. - (void)applicationWillEnterForeground:(UIApplication *)application {
  115. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
  116. }
  117. - (void)applicationDidBecomeActive:(UIApplication *)application {
  118. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  119. }
  120. - (void)applicationWillTerminate:(UIApplication *)application {
  121. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  122. }
  123. -(void) Login:(NSString* )user pwd:(NSString*) pwd
  124. {
  125. self.user = user;
  126. self.password = pwd;
  127. self.bLogin = true;
  128. }
  129. -(void) Logout
  130. {
  131. // MainViewController * main_vc= (MainViewController*)self.main_vc;
  132. // [main_vc logoutOrder];
  133. //
  134. //
  135. // [main_vc hideMenu];
  136. // [main_vc switchToHome];
  137. self.user = nil;
  138. self.password=nil;
  139. self.bLogin = false;
  140. // self.user_icon=nil;
  141. // self.user_type = USER_ROLE_UNKNOWN;
  142. // self.bLogin = false;
  143. // self.contact_id=nil;
  144. // self.customerInfo = nil;
  145. // self.order_code = nil;
  146. //
  147. // [self.recent_model removeAllObjects];
  148. //
  149. // [self SetMode:nil];
  150. }
  151. @end