AppDelegate.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 "LoginViewController.h"
  15. #import "RootViewController.h"
  16. //#import "AFHTTPSessionManager.h"
  17. @interface AppDelegate ()
  18. @end
  19. @implementation AppDelegate
  20. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  21. // Override point for customization after application launch.
  22. self.bEnable_Cache = true;
  23. [self function_test];
  24. return YES;
  25. }
  26. -(NSString*) filetype:(NSString*)filePath
  27. {
  28. NSString *suffix = [filePath pathExtension];
  29. if([suffix.lowercaseString isEqualToString:@"jpg"]||[suffix.lowercaseString isEqualToString:@"png"]||[suffix.lowercaseString isEqualToString:@"bmp"]||[suffix.lowercaseString isEqualToString:@"gif"])
  30. return @"image";
  31. else
  32. return @"file";
  33. }
  34. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options
  35. {
  36. NSLog(@"URL:%@, OPTIONS:%@",[url absoluteString],[RAUtils dict2string:options]);
  37. NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
  38. item[@"type"]=[self filetype:url.absoluteString];
  39. item[@"url"]= [url path];
  40. item[@"file_name"] = [url.absoluteString lastPathComponent];
  41. if(self.bLogin)
  42. {
  43. UINavigationController *rootVC = (UINavigationController *)application.keyWindow.rootViewController;
  44. UIViewController* presentVC=rootVC.presentedViewController;
  45. AddExtDocumentViewController * addVC;
  46. if([presentVC isKindOfClass:[UINavigationController class]])
  47. {
  48. //如果当前已有模态对话框,则关闭当前的模态框,否则无法弹出上传框。
  49. UIViewController* topvc= ((UINavigationController*)presentVC).topViewController;
  50. if([topvc isKindOfClass:[AddExtDocumentViewController class]])
  51. {
  52. addVC = (AddExtDocumentViewController*)topvc;
  53. if(addVC.arr_documents==nil)
  54. addVC.arr_documents = [NSMutableArray arrayWithObjects:item, nil];
  55. else
  56. [addVC.arr_documents addObject:item];
  57. [addVC refresh_table];
  58. }
  59. else
  60. [presentVC dismissViewControllerAnimated:false completion:nil];
  61. }
  62. else
  63. {
  64. addVC = [ [UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AddExtDocumentViewController"];
  65. addVC.is_present = true;
  66. addVC.doc_number = nil;
  67. addVC.arr_documents = [NSMutableArray arrayWithObjects:item, nil];
  68. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:addVC] ;
  69. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  70. [rootVC presentViewController:navi animated:YES completion:^{
  71. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  72. DebugLog(@"filter present.........");
  73. // self.btop = false;
  74. // <#code#>
  75. }];
  76. }
  77. }
  78. else
  79. {
  80. self.shareFile = item;
  81. UINavigationController *rootVC = (UINavigationController *)application.keyWindow.rootViewController;
  82. RootViewController* topvc= (RootViewController*)rootVC.topViewController;
  83. UIViewController* presentVC=rootVC.presentedViewController;
  84. // AddExtDocumentViewController * addVC;
  85. if(!presentVC)//([presentVC isKindOfClass:[UINavigationController class]])
  86. {
  87. //未弹出login 框
  88. [topvc presentLogin:topvc.ibSignin];
  89. }
  90. }
  91. // [ pushViewController:addVC animated:false];
  92. // return YES;
  93. return YES;
  94. }
  95. -(void)function_test
  96. {
  97. return;
  98. printf("function test======================");
  99. // NSString* pdffile = [PDFUtils SavePDF:nil source:nil window_rect:CGRectMake(0, 0, 768, 960)];
  100. // [PDFUtils leak_test];
  101. // 获取路径
  102. NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
  103. NSString *saveDirectory=[paths objectAtIndex:0];
  104. NSString *saveFileName=[NSString stringWithFormat:@"%@.pdf",[[NSUUID UUID ] UUIDString] ] ;;
  105. NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
  106. const char *filename=[newFilePath UTF8String];
  107. NSLog(@"%@",newFilePath);
  108. //设置页面大小 Letter纸
  109. CFStringRef path;
  110. CFURLRef url;
  111. path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
  112. url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
  113. CFRelease(path);
  114. // CGPDFCONTEXTCREATE
  115. CGContextRef pdfContext;
  116. CGRect docsize = CGRectMake(0, 0, 612, 1008);
  117. CFMutableDictionaryRef myDictionary = NULL;
  118. myDictionary= CFDictionaryCreateMutable(NULL,
  119. 0,
  120. NULL,
  121. NULL);
  122. CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("usai2010"));
  123. CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanTrue);
  124. CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
  125. pdfContext=CGPDFContextCreateWithURL(url, &docsize,myDictionary);
  126. CFRelease(myDictionary);
  127. CFRelease(url);
  128. CGContextBeginPage(pdfContext, &docsize);
  129. // cgpdfpage
  130. CGContextEndPage(pdfContext);
  131. CGPDFContextClose(pdfContext);
  132. CGContextRelease(pdfContext);
  133. return ;
  134. }
  135. - (void)applicationWillResignActive:(UIApplication *)application {
  136. // 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.
  137. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  138. }
  139. - (void)applicationDidEnterBackground:(UIApplication *)application {
  140. // 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.
  141. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  142. }
  143. - (void)applicationWillEnterForeground:(UIApplication *)application {
  144. // 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.
  145. }
  146. - (void)applicationDidBecomeActive:(UIApplication *)application {
  147. // 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.
  148. }
  149. - (void)applicationWillTerminate:(UIApplication *)application {
  150. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  151. }
  152. -(void) Login:(NSString* )user pwd:(NSString*) pwd
  153. {
  154. self.user = user;
  155. self.password = pwd;
  156. self.bLogin = true;
  157. }
  158. -(void) Logout
  159. {
  160. // MainViewController * main_vc= (MainViewController*)self.main_vc;
  161. // [main_vc logoutOrder];
  162. //
  163. //
  164. // [main_vc hideMenu];
  165. // [main_vc switchToHome];
  166. self.user = nil;
  167. self.password=nil;
  168. self.bLogin = false;
  169. // self.user_icon=nil;
  170. // self.user_type = USER_ROLE_UNKNOWN;
  171. // self.bLogin = false;
  172. // self.contact_id=nil;
  173. // self.customerInfo = nil;
  174. // self.order_code = nil;
  175. //
  176. // [self.recent_model removeAllObjects];
  177. //
  178. // [self SetMode:nil];
  179. }
  180. @end