RAUtils.m 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. //
  2. // RAUtils.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 9/17/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RAUtils.h"
  9. #import "RAConvertor.h"
  10. #import "const.h"
  11. //#import "LoginViewController.h"
  12. //#import "MainViewController.h"
  13. #import <sys/param.h>
  14. #import <sys/mount.h>
  15. //#import "const.h"
  16. #import "AppDelegate.h"
  17. //#import "Singleton.h"
  18. #include <CommonCrypto/CommonDigest.h>
  19. //#import "ZipArchive.h"
  20. #define FileHashDefaultChunkSizeForReadingData 1024*8
  21. @implementation RAUtils
  22. +(int)getRandomNumber:(int)from to:(int)to
  23. {
  24. return (int)(from + (arc4random() % (to-from + 1)));
  25. }
  26. //+(float)randomf
  27. //{
  28. //
  29. // int irandom = [self getRandomNumber:0 to:5];
  30. // return irandom / 100.0;
  31. //}
  32. +(NSData*) getdbfile:(NSString*)dbname
  33. {
  34. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  35. NSString *documents = /*[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];*/[paths objectAtIndex:0];
  36. NSString *database_path = [documents stringByAppendingPathComponent:dbname];
  37. return [NSData dataWithContentsOfFile:database_path];
  38. }
  39. +(NSDictionary*) dictfromfile:(NSString*) path
  40. {
  41. NSData *filedata = [NSData dataWithContentsOfFile:path];
  42. if(filedata == nil)
  43. return nil;
  44. NSError *error = nil;
  45. NSDictionary *string2dic = [NSJSONSerialization JSONObjectWithData: filedata
  46. options: NSJSONReadingMutableContainers
  47. error: &error];
  48. // DebugLog(@"%@",string2dic);
  49. return string2dic;
  50. }
  51. +(void) dicttofile:(NSString*) path dict:(NSDictionary*)dict
  52. {
  53. NSDictionary* saveddict = dict;
  54. if(saveddict==nil)
  55. return;
  56. NSString *filestr =[RAConvertor dict2string:dict];
  57. NSError *error=nil;
  58. [filestr writeToFile:path atomically:true encoding:NSUTF8StringEncoding error:&error];
  59. // DebugLog(@"%@",string2dic);
  60. // return string2dic;
  61. }
  62. +(NSDictionary* )copyDict:(NSDictionary* ) source
  63. {
  64. return [RAConvertor data2dict:[RAConvertor dict2data:source]];
  65. }
  66. + (NSArray*) allFilesAtPath:(NSString*) dirString
  67. {
  68. NSMutableArray* array = [NSMutableArray arrayWithCapacity:10];
  69. NSFileManager* fileMgr = [NSFileManager defaultManager];
  70. NSArray* tempArray = [fileMgr contentsOfDirectoryAtPath:dirString error:nil];
  71. for (NSString* fileName in tempArray) {
  72. BOOL flag = YES;
  73. NSString* fullPath = [dirString stringByAppendingPathComponent:fileName];
  74. if ([fileMgr fileExistsAtPath:fullPath isDirectory:&flag]) {
  75. if (!flag) {
  76. [array addObject:fullPath];
  77. }
  78. }
  79. }
  80. return array;
  81. }
  82. + (bool)mergeContentsOfPath:(NSString *)srcDir intoPath:(NSString *)dstDir error:(NSError**)err {
  83. DebugLog(@"- mergeContentsOfPath: %@\n intoPath: %@", srcDir, dstDir);
  84. NSFileManager *fm = [NSFileManager defaultManager];
  85. NSDirectoryEnumerator *srcDirEnum = [fm enumeratorAtPath:srcDir];
  86. NSString *subPath;
  87. while ((subPath = [srcDirEnum nextObject])) {
  88. DebugLog(@" subPath: %@", subPath);
  89. NSString *srcFullPath = [srcDir stringByAppendingPathComponent:subPath];
  90. NSString *potentialDstPath = [dstDir stringByAppendingPathComponent:subPath];
  91. // Need to also check if file exists because if it doesn't, value of `isDirectory` is undefined.
  92. BOOL isDirectory = ([[NSFileManager defaultManager] fileExistsAtPath:srcFullPath isDirectory:&isDirectory] && isDirectory);
  93. // Create directory, or delete existing file and move file to destination
  94. if (isDirectory) {
  95. DebugLog(@" create directory");
  96. [fm createDirectoryAtPath:potentialDstPath withIntermediateDirectories:YES attributes:nil error:err];
  97. if (err && *err) {
  98. DebugLog(@"ERROR: %@", *err);
  99. return false;
  100. }
  101. }
  102. else {
  103. if ([fm fileExistsAtPath:potentialDstPath]) {
  104. DebugLog(@" removeItemAtPath");
  105. [fm removeItemAtPath:potentialDstPath error:err];
  106. if (err && *err) {
  107. DebugLog(@"ERROR: %@", *err);
  108. return false;
  109. }
  110. }
  111. DebugLog(@" moveItemAtPath");
  112. [fm moveItemAtPath:srcFullPath toPath:potentialDstPath error:err];
  113. if (err && *err) {
  114. DebugLog(@"ERROR: %@", *err);
  115. return false;
  116. }
  117. }
  118. }
  119. [fm removeItemAtPath:srcDir error:err];
  120. if (err && *err) {
  121. DebugLog(@"ERROR: %@", *err);
  122. return false;
  123. }
  124. return true;
  125. }
  126. //+(void) enum_font
  127. //{
  128. // return;
  129. // NSArray *familys = [UIFont familyNames];
  130. //
  131. // for (int i = 0; i < familys.count; i++)
  132. // {
  133. // NSString *family = [familys objectAtIndex:i];
  134. // DebugLog(@"=====Fontfamily:%@", family);
  135. // NSArray *fonts = [UIFont fontNamesForFamilyName:family];
  136. // for(int j = 0; j < fonts.count; j++)
  137. // {
  138. // DebugLog(@"***FontName:%@", [fonts objectAtIndex:j]);
  139. // }
  140. // }
  141. //}
  142. //+(NSTextCheckingResult*) expression_findfistMatch:(NSString*)content regex:(NSString*) pattern
  143. //{
  144. // NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:nil];
  145. //
  146. // NSTextCheckingResult *match = [regex firstMatchInString:content options:0 range:NSMakeRange(0, content.length)];
  147. // return match;
  148. //// if (matches) {
  149. //// for (NSTextCheckingResult *match in matches) {
  150. //// for (int i = 0; i < match.numberOfRanges; ++i) {
  151. //// DebugLog(@"-> %@", [content substringWithRange:[match rangeAtIndex:i]]);
  152. //// }
  153. //// }
  154. //// }
  155. //// return matches;
  156. //}
  157. //+(NSArray*) expression_varable:(NSString*)content regex:(NSString*) pattern
  158. //{
  159. //
  160. // if(content==nil)
  161. // return nil;
  162. //
  163. //
  164. // NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:nil];
  165. //
  166. // NSArray *matches = [regex matchesInString:content options:0 range:NSMakeRange(0, content.length)];
  167. //
  168. // if (matches) {
  169. // for (NSTextCheckingResult *match in matches) {
  170. // for (int i = 0; i < match.numberOfRanges; ++i) {
  171. // DebugLog(@"-> %@", [content substringWithRange:[match rangeAtIndex:i]]);
  172. // }
  173. // }
  174. // }
  175. // return matches;
  176. //}
  177. + (CGRect)rectAlign:(CGRect )parent rect:(CGRect)rect hAlign:(NSString*)hAlign vAlign:(NSString*)vAlign
  178. {
  179. // double cx=parent.origin.x+parent.size.width/2;
  180. // double cy=parent.origin.y+parent.size.height/2;
  181. CGPoint centerpoint= CGPointMake(parent.origin.x+parent.size.width/2,parent.origin.y+parent.size.height/2);
  182. if([hAlign.lowercaseString isEqualToString:@"center"])
  183. {
  184. rect=CGRectMake(centerpoint.x-rect.size.width/2, rect.origin.y, rect.size.width, rect.size.height);
  185. }
  186. else
  187. if([hAlign.lowercaseString isEqualToString:@"left"])
  188. {
  189. rect=CGRectMake(parent.origin.x, rect.origin.y, rect.size.width, rect.size.height);
  190. }
  191. else
  192. if([hAlign.lowercaseString isEqualToString:@"right"])
  193. {
  194. rect=CGRectMake(parent.origin.x+parent.size.width-rect.size.width, rect.origin.y, rect.size.width, rect.size.height);
  195. }
  196. if([vAlign.lowercaseString isEqualToString:@"middle"])
  197. {
  198. rect=CGRectMake(rect.origin.x, centerpoint.y-rect.size.height/2, rect.size.width, rect.size.height);
  199. }
  200. return rect;
  201. }
  202. +(NSString*) get_config_path
  203. {
  204. NSString *default_path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
  205. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  206. NSString *cache_folder=[paths objectAtIndex:0];
  207. NSString* ver=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
  208. NSString *config_path = [cache_folder stringByAppendingPathComponent:[NSString stringWithFormat: @"config_%@.plist",ver]];
  209. BOOL bdir=NO;
  210. NSFileManager* fileManager = [NSFileManager defaultManager];
  211. if(! [fileManager fileExistsAtPath:config_path isDirectory:&bdir])
  212. {
  213. NSError * error=nil;
  214. if(![fileManager copyItemAtPath:default_path toPath:config_path error:&error])
  215. {
  216. return nil;
  217. }
  218. }
  219. return config_path;
  220. }
  221. + (CGRect)rectVAlign:(CGRect )parent rect:(CGRect)rect vAlign:(NSString*)vAlign
  222. {
  223. // double cx=parent.origin.x+parent.size.width/2;
  224. // double cy=parent.origin.y+parent.size.height/2;
  225. CGPoint centerpoint= CGPointMake(parent.origin.x+parent.size.width/2,parent.origin.y+parent.size.height/2);
  226. if([vAlign.lowercaseString isEqualToString:@"middle"])
  227. {
  228. rect=CGRectMake(rect.origin.x, centerpoint.y-rect.size.height/2, rect.size.width, rect.size.height);
  229. }
  230. return rect;
  231. }
  232. + (CGRect)scaleToSize:(CGRect )from to:(CGSize)to
  233. {
  234. if(from.size.width/from.size.height>to.width/to.height)
  235. {
  236. return CGRectMake(from.origin.x, from.origin.y, to.width, to.width*from.size.height/from.size.width);
  237. }
  238. else
  239. {
  240. return CGRectMake(from.origin.x, from.origin.y, to.height*from.size.width/from.size.height, to.height);
  241. }
  242. // // 创建一个bitmap的context
  243. // // 并把它设置成为当前正在使用的context
  244. // UIGraphicsBeginImageContext(size);
  245. // // 绘制改变大小的图片
  246. // [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
  247. // // 从当前context中创建一个改变大小后的图片
  248. // UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  249. // // 使当前的context出堆栈
  250. // UIGraphicsEndImageContext();
  251. // // 返回新的改变大小后的图片
  252. //
  253. // // NSData *imageData=UIImageJPEGRepresentation(scaledImage, 1.f);
  254. // return scaledImage;
  255. }
  256. + (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
  257. // 创建一个bitmap的context
  258. // 并把它设置成为当前正在使用的context
  259. UIGraphicsBeginImageContext(size);
  260. // 绘制改变大小的图片
  261. [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
  262. // 从当前context中创建一个改变大小后的图片
  263. UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  264. // 使当前的context出堆栈
  265. UIGraphicsEndImageContext();
  266. // 返回新的改变大小后的图片
  267. // NSData *imageData=UIImageJPEGRepresentation(scaledImage, 1.f);
  268. return scaledImage;
  269. }
  270. +(UIImage*)img_compress:(UIImage*)image kbsize:(float) size
  271. {
  272. //UIImage *image=[UIImage imageNamed:@"xxoo.jpeg"];
  273. NSData *imageData=UIImageJPEGRepresentation(image, 1.f);
  274. if(size>imageData.length/1024)
  275. return image;
  276. // CGFloat size=40.f;// kb
  277. CGFloat scale=size/(imageData.length/1024);
  278. scale = sqrt (scale);
  279. CGSize newsize=image.size;
  280. newsize.height = newsize.height*scale;
  281. newsize.width = newsize.width*scale;
  282. return [RAUtils scaleToSize:image size:newsize];
  283. // NSData *newData=UIImageJPEGRepresentation(image, scale);
  284. // UIImage* ret= [[UIImage alloc] initWithData:newData];
  285. //
  286. // return ret;
  287. }
  288. +(NSString*) FloatFormat:(float)value
  289. {
  290. if (fmodf(value, 1)==0)
  291. {
  292. return [NSString stringWithFormat:@"%.0f",value];
  293. } else if (fmodf(value*10, 1)==0)
  294. {
  295. return [NSString stringWithFormat:@"%.1f",value];
  296. }
  297. else if (fmodf(value*100, 1)==0)
  298. {
  299. return [NSString stringWithFormat:@"%.2f",value];
  300. }
  301. else if (fmodf(value*1000, 1)==0)
  302. {
  303. return [NSString stringWithFormat:@"%.3f",value];
  304. }
  305. else
  306. {
  307. return [NSString stringWithFormat:@"%.4f",value];
  308. }
  309. return nil;
  310. }
  311. +(UIViewController*) getViewController:(UIView*) view
  312. {
  313. for (UIView* next = [view superview]; next; next = next.superview) {
  314. UIResponder* nextResponder = [next nextResponder];
  315. if ([nextResponder isKindOfClass:[UIViewController class]]) {
  316. return (UIViewController*)nextResponder;
  317. }
  318. }
  319. return nil;
  320. }
  321. + (float)fileSizeForDir:(NSString*)path//计算文件夹下文件的总大小
  322. {
  323. NSFileManager *fileManager = [[NSFileManager alloc] init];
  324. float size =0;
  325. NSArray* array = [fileManager contentsOfDirectoryAtPath:path error:nil];
  326. for(int i = 0; i<[array count]; i++)
  327. {
  328. NSString *fullPath = [path stringByAppendingPathComponent:[array objectAtIndex:i]];
  329. BOOL isDir;
  330. if ( !([fileManager fileExistsAtPath:fullPath isDirectory:&isDir] && isDir) )
  331. {
  332. NSDictionary *fileAttributeDic=[fileManager attributesOfItemAtPath:fullPath error:nil];
  333. size+= fileAttributeDic.fileSize/ 1024.0/1024.0;
  334. }
  335. else
  336. {
  337. size+=[self fileSizeForDir:fullPath];
  338. }
  339. }
  340. return size;
  341. }
  342. /*创建错误信息字典*/
  343. +(NSDictionary*) error_dict:(NSError*)error
  344. {
  345. if(error==nil)
  346. return nil;
  347. NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  348. [ret setValue:[NSString stringWithFormat:@"%ld",(long)error.code] forKey:@"error_code"];
  349. [ret setValue:error.domain forKey:@"err_domain"];
  350. [ret setValue:[error localizedDescription] forKey:@"err_message"];
  351. // [ret setObject:error.userInfo forKey:@"user_info"];
  352. return ret;
  353. }
  354. +(NSString*) current_date
  355. {
  356. NSDate * date = [NSDate date];
  357. NSTimeInterval sec = [date timeIntervalSinceNow];
  358. NSDate * currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec];
  359. NSDateFormatter * df = [[NSDateFormatter alloc] init ];
  360. [df setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
  361. NSString * na = [df stringFromDate:currentDate];
  362. return na;
  363. }
  364. +(NSString*) current_date_time
  365. {
  366. NSDate * date = [NSDate date];
  367. NSTimeInterval sec = [date timeIntervalSinceNow];
  368. NSDate * currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec];
  369. NSDateFormatter * df = [[NSDateFormatter alloc] init ];
  370. [df setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
  371. NSString * na = [df stringFromDate:currentDate];
  372. return na;
  373. }
  374. +(NSString*) current_date_forfile
  375. {
  376. NSDate * date = [NSDate date];
  377. NSTimeInterval sec = [date timeIntervalSinceNow];
  378. NSDate * currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec];
  379. NSDateFormatter * df = [[NSDateFormatter alloc] init ];
  380. [df setDateFormat:@"MM_dd_yyyy_HH_mm_ss"];
  381. NSString * na = [df stringFromDate:currentDate];
  382. return na;
  383. }
  384. //+(void) message_alert :(NSString*) msg title:(NSString*) title controller:(UIViewController*) vc
  385. //{
  386. // if(title==nil)
  387. // title = @"Message";
  388. // if ([title isEqualToString:@"Add To Cart"]) {
  389. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  390. // title = @"Add To Cart: Out of Stock";
  391. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  392. // }
  393. // }
  394. //
  395. //
  396. //
  397. // return [self alert_view:msg title:title];
  398. ////
  399. ////
  400. //// UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  401. //// //block代码块取代了delegate
  402. ////
  403. ////
  404. //// // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  405. //// // textField.text = self.save_name;
  406. //// //
  407. //// //
  408. //// // }];
  409. ////
  410. //// // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  411. //// //
  412. //// // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Order"];
  413. //// // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  414. //// //
  415. //// // NSDictionary* return_json = [iSalesNetwork delete_Order:orderid];
  416. //// //
  417. //// // dispatch_async(dispatch_get_main_queue(), ^{
  418. //// // [waitalert dismissViewControllerAnimated:YES completion:nil];
  419. //// //
  420. //// //
  421. //// // if([[return_json valueForKey:@"result"] intValue]==2)
  422. //// // {
  423. //// //
  424. //// // [RAUtils error_alert:nil title:@"Order Delete"] ;
  425. //// // }
  426. //// // else
  427. //// // {
  428. //// // [RAUtils error_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order Failed."] ;
  429. //// // }
  430. //// //
  431. //// //
  432. //// //
  433. //// //
  434. //// // });
  435. //// // });
  436. //// //
  437. //// //
  438. //// // }];
  439. ////
  440. //// UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  441. //// //DebugLog(@"Cancel");
  442. //// }];
  443. //// // [alertControl addAction:actionOne];
  444. ////
  445. //// [alertControl addAction:alertthree];
  446. ////
  447. ////
  448. //// UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  449. //// }];
  450. //// [alertControl addAction:alertcancel];
  451. //// //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  452. ////
  453. ////
  454. ////
  455. ////
  456. //// [vc presentViewController:alertControl animated:YES completion:nil];
  457. ////
  458. ////
  459. ////
  460. //// return;
  461. ////
  462. ////
  463. //
  464. //
  465. //}
  466. //+(void) alert_view :(NSString*) msg title:(NSString*) title
  467. //{
  468. // if(title==nil)
  469. // title = NSLocalizedString(@"Message", @"Message");
  470. // if(msg.length>0)
  471. // {
  472. // title=[NSString stringWithFormat:@"%@\n\n%@",title,msg];
  473. // }
  474. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:nil delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok", @"Ok") otherButtonTitles:nil, nil];
  475. // [alert show];
  476. //}
  477. + (long long) freeDiskSpaceInMegaBytes{
  478. struct statfs buf;
  479. long long freespace = -1;
  480. if(statfs("/var", &buf) >= 0){
  481. freespace = (long long)(buf.f_bsize * buf.f_bfree);
  482. }
  483. DebugLog(@"手机剩余存储空间为:%qi MB" ,freespace/1024/1024);
  484. return freespace/1024/1024;
  485. }
  486. //+(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*) title
  487. //{
  488. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
  489. //
  490. //// [parent presentModalViewController:alertController animated:YES];
  491. // [parent presentViewController:alertController animated:YES completion:nil];
  492. // return alertController;
  493. //
  494. //}
  495. +(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*) title completion:(void (^ __nullable)(void))completion
  496. {
  497. return [self waiting_alert:parent message:@"Please wait..." title:title completion:completion];
  498. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
  499. //
  500. // [parent presentViewController:alertController animated:YES completion:completion];
  501. // return alertController;
  502. }
  503. //+(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*)msg title:(NSString*) title
  504. //{
  505. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
  506. // [parent presentViewController:alertController animated:YES completion:nil];
  507. // return alertController;
  508. //
  509. //}
  510. +(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*)msg title:(NSString*) title completion:(void (^ __nullable)(void))completion
  511. {
  512. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
  513. [parent presentViewController:alertController animated:YES completion:completion];
  514. NSLog(@"show waiting alert %p",alertController);
  515. return alertController;
  516. }
  517. +(UIAlertController*) message_alert :(NSString*) msg title:(NSString*) title controller:(UIViewController*) vc
  518. {
  519. if(title==nil)
  520. title = @"Message";
  521. if ([title isEqualToString:@"Add To Cart"]) {
  522. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  523. title = @"Add To Cart: Out of Stock";
  524. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  525. }
  526. }
  527. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
  528. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
  529. [alertController addAction:action_0];
  530. [vc presentViewController:alertController animated:YES completion:nil];
  531. NSLog(@"show message alert %p",alertController);
  532. return alertController;
  533. }
  534. +(UIAlertController*) message_alert :(NSString*) msg title:(NSString*) title controller:(UIViewController*) vc action_handler:(void (^ __nullable)(UIAlertAction *action))action_handler completion:(void (^ __nullable)(void))completion
  535. {
  536. if(title==nil)
  537. title = @"Message";
  538. if ([title isEqualToString:@"Add To Cart"]) {
  539. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  540. title = @"Add To Cart: Out of Stock";
  541. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  542. }
  543. }
  544. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
  545. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:action_handler];
  546. [alertController addAction:action_0];
  547. [vc presentViewController:alertController animated:YES completion:completion];
  548. NSLog(@"show message alert %p",alertController);
  549. return alertController;
  550. }
  551. //+(UIAlertView * ) waiting_alert :(NSString*) msg title:(NSString*) title
  552. //{
  553. // if(title==nil)
  554. // title = @"Please Wait";
  555. // if(msg==nil)
  556. // msg= @"Waiting...";
  557. // NSAssert(msg!=nil, @"error message from json is nil");
  558. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
  559. // [alert show];
  560. // //
  561. // //
  562. // // UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125.0, 80.0, 30.0, 30.0)];
  563. // // aiView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
  564. // // // check if os version is 7 or above. ios7.0及以上UIAlertView弃用了addSubview方法
  565. // //// if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending) {
  566. // //// [alert setValue:aiView forKey:@"accessoryView"];
  567. // //// }else{
  568. // //// [alert addSubview:aiView];
  569. // //// }
  570. // //
  571. // // aiView.hidden = false;
  572. // // aiView.hidesWhenStopped = false;
  573. // // [aiView startAnimating];
  574. // //
  575. // //[alert addSubview:aiView];
  576. //
  577. // return alert;
  578. // //return nil;
  579. // // return alert;
  580. // // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  581. // //[alert show];
  582. //}
  583. +(NSDictionary*) device_info
  584. {
  585. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  586. NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
  587. NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  588. NSString* versionNum = [NSString stringWithFormat:@"Version: %@ Build %@",version,build];
  589. NSMutableDictionary * info = [[NSMutableDictionary alloc]init];
  590. [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
  591. [info setValue:[[UIDevice currentDevice] systemVersion] forKey:@"systemVersion"];
  592. [info setValue:[[UIDevice currentDevice] model] forKey:@"model"];
  593. [info setValue:versionNum forKey:@"ver"];
  594. [info setValue:[[UIDevice currentDevice] localizedModel] forKey:@"localizedModel"];
  595. return info;
  596. // [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
  597. // [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
  598. // [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
  599. }
  600. + (NSString *)deviceID {
  601. UIDevice * dev = [UIDevice currentDevice];
  602. NSUUID* uuid =dev.identifierForVendor;
  603. return uuid.UUIDString;
  604. }
  605. //+(NSArray*) string2arr:(NSString*) string separator:(NSString*)separator
  606. //{
  607. // NSArray *stringArray = [string componentsSeparatedByString:separator];
  608. //
  609. // return stringArray;
  610. //}
  611. +(NSDictionary*) string2dict:(NSString*) str
  612. {
  613. if(str==nil)
  614. return nil;
  615. NSError *error = nil;
  616. NSDictionary *string2dic = [NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding:NSUTF8StringEncoding]
  617. options: NSJSONReadingMutableContainers
  618. error: &error];
  619. DebugLog(@"%@",string2dic);
  620. return string2dic;
  621. }
  622. +(UIColor*) strColor:(NSString*) color
  623. {
  624. if([color.lowercaseString isEqualToString:@"red"])
  625. return [UIColor redColor];
  626. return [UIColor blackColor];
  627. }
  628. +(NSString*) base64en:(NSString*) string
  629. {
  630. if(string == nil)
  631. return nil;
  632. NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
  633. NSString *stringBase64 = [data base64EncodedStringWithOptions:0]; // base64格式的字符串
  634. return stringBase64;
  635. }
  636. +(NSString*) base64de:(NSString*) stringBase64
  637. {
  638. if(stringBase64==nil)
  639. return nil;
  640. NSData *data = [[NSData alloc] initWithBase64EncodedString:stringBase64 options:NSDataBase64DecodingIgnoreUnknownCharacters];
  641. NSString *string =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  642. return string;
  643. }
  644. +(void) deletefiles :(NSString*) path
  645. {
  646. // NSString *extension = @"m4r";
  647. NSFileManager *fileManager = [NSFileManager defaultManager];
  648. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  649. // NSString *documentsDirectory = [paths objectAtIndex:0];
  650. NSArray *contents = [fileManager contentsOfDirectoryAtPath:path error:NULL];
  651. NSEnumerator *e = [contents objectEnumerator];
  652. NSString *filename;
  653. while ((filename = [e nextObject])) {
  654. bool result= [fileManager removeItemAtPath:[path stringByAppendingPathComponent:filename] error:NULL];
  655. if(!result)
  656. DebugLog(@"delete file failed %@------%@",path,filename);
  657. }
  658. }
  659. +(NSMutableArray*)dictionary2array:(NSDictionary*)json count_fields:(NSString*) count_fields item_mark:(NSString*) item_mark items_mark:(NSString* )items_mark
  660. {
  661. if(json==nil)
  662. return nil;
  663. NSMutableArray* ret = [[NSMutableArray alloc] init];
  664. int count = [[json valueForKey:count_fields] intValue];
  665. NSDictionary* items = nil;
  666. if(items_mark==nil)
  667. items = json;
  668. else
  669. items = [json objectForKey:items_mark];
  670. for(int i=0;i<count;i++)
  671. {
  672. NSDictionary* obj = [items objectForKey:[NSString stringWithFormat:@"%@%d",item_mark,i]];
  673. [ret addObject:obj];
  674. }
  675. return ret;
  676. }
  677. +(NSDictionary*) error_json :(int)code err_msg:(NSString*)msg
  678. {
  679. NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  680. //#define RESULT_FALSE 0
  681. //#define RESULT_TRUE 2
  682. //#define RESULT_NET_ERROR -3
  683. //#define RESULT_NET_NOTAVAILABLE -4
  684. //#define RESULT_ERROR -5
  685. //#define RESULT_LOCALFILE_ERROR -7
  686. //#define RESULT_USERAUTH_ERROR -9
  687. //#define RESULT_UPDATE_USERAUTH_ERROR -11
  688. //#define RESULT_SESSION_EXPIRED -13
  689. //#define RESULT_VER_LOW
  690. if(msg.length<=0)
  691. {
  692. switch (code) {
  693. case RESULT_NET_NOTAVAILABLE:
  694. msg= MSG_NET_NOTAVAILABLE;
  695. break;
  696. default:
  697. // assert(@"UNDEFINE ERROR CODE!");
  698. break;
  699. }
  700. }
  701. // if(code==RESULT_NET_NOTAVAILABLE)
  702. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  703. // else
  704. [ret setValue:[NSString stringWithFormat:@"%d",code] forKey:@"result"];
  705. [ret setValue:msg forKey:@"err_msg"];
  706. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  707. // options:0
  708. // error:nil];
  709. return ret;
  710. }
  711. + (BOOL)isNumeric:(NSString*)string{
  712. NSScanner* scan = [NSScanner scannerWithString:string];
  713. int val;
  714. return[scan scanInt:&val] && [scan isAtEnd];
  715. }
  716. + (CGRect)relativeFrame:(CGRect) frame FromView:(UIView *)v toView:(UIView*)tv
  717. {
  718. return [v convertRect: frame toView:tv];
  719. }
  720. + (CGRect)relativeFrameForScreenWithView:(UIView *)v
  721. {
  722. UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
  723. CGRect rect=[v convertRect: v.bounds toView:window];
  724. return rect;
  725. // BOOL iOS7 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 7;
  726. //
  727. // CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
  728. // if (!iOS7) {
  729. // screenHeight -= 20;
  730. // }
  731. // UIView *view = v;
  732. // CGFloat x = .0;
  733. // CGFloat y = .0;
  734. // while (view.frame.size.width != 320 || view.frame.size.height != screenHeight) {
  735. // x += view.frame.origin.x;
  736. // y += view.frame.origin.y;
  737. // view = view.superview;
  738. // if ([view isKindOfClass:[UIScrollView class]]) {
  739. // x -= ((UIScrollView *) view).contentOffset.x;
  740. // y -= ((UIScrollView *) view).contentOffset.y;
  741. // }
  742. // }
  743. // return CGRectMake(x, y, v.frame.size.width, v.frame.size.height);
  744. }
  745. + (BOOL)saveData:(NSData *)data toPath:(NSString *)path {
  746. // NSString *directory = [path stringByDeletingLastPathComponent];
  747. NSFileManager *manager = [NSFileManager defaultManager];
  748. NSString *dir = [path stringByDeletingLastPathComponent];
  749. BOOL create = [manager createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  750. if (create) {
  751. BOOL save = [manager createFileAtPath:path contents:data attributes:nil];
  752. if (save) {
  753. return YES;
  754. }
  755. return NO;
  756. }
  757. return NO;
  758. }
  759. + (void)removeFileAtPath:(NSString *)path {
  760. if (!path.length) {
  761. return;
  762. }
  763. NSFileManager *manager = [NSFileManager defaultManager];
  764. [manager removeItemAtPath:path error:nil];
  765. }
  766. + (NSString *)appCacheDirectory {
  767. return [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
  768. }
  769. +(NSString*)md5WithFile:(NSString*)path
  770. {
  771. return (__bridge_transfer NSString *)FileMD5HashCreateWithPath((__bridge CFStringRef)path, FileHashDefaultChunkSizeForReadingData);
  772. }
  773. CFStringRef FileMD5HashCreateWithPath(CFStringRef filePath,size_t chunkSizeForReadingData) {
  774. // Declare needed variables
  775. CFStringRef result = NULL;
  776. CFReadStreamRef readStream = NULL;
  777. // Get the file URL
  778. CFURLRef fileURL =
  779. CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
  780. (CFStringRef)filePath,
  781. kCFURLPOSIXPathStyle,
  782. (Boolean)false);
  783. if (!fileURL) goto done;
  784. // Create and open the read stream
  785. readStream = CFReadStreamCreateWithFile(kCFAllocatorDefault,
  786. (CFURLRef)fileURL);
  787. if (!readStream) goto done;
  788. bool didSucceed = (bool)CFReadStreamOpen(readStream);
  789. if (!didSucceed) goto done;
  790. // Initialize the hash object
  791. CC_MD5_CTX hashObject;
  792. CC_MD5_Init(&hashObject);
  793. // Make sure chunkSizeForReadingData is valid
  794. if (!chunkSizeForReadingData) {
  795. chunkSizeForReadingData = FileHashDefaultChunkSizeForReadingData;
  796. }
  797. // Feed the data to the hash object
  798. bool hasMoreData = true;
  799. while (hasMoreData) {
  800. uint8_t buffer[chunkSizeForReadingData];
  801. CFIndex readBytesCount = CFReadStreamRead(readStream,(UInt8 *)buffer,(CFIndex)sizeof(buffer));
  802. if (readBytesCount == -1) break;
  803. if (readBytesCount == 0) {
  804. hasMoreData = false;
  805. continue;
  806. }
  807. CC_MD5_Update(&hashObject,(const void *)buffer,(CC_LONG)readBytesCount);
  808. }
  809. // Check if the read operation succeeded
  810. didSucceed = !hasMoreData;
  811. // Compute the hash digest
  812. unsigned char digest[CC_MD5_DIGEST_LENGTH];
  813. CC_MD5_Final(digest, &hashObject);
  814. // Abort if the read operation failed
  815. if (!didSucceed) goto done;
  816. // Compute the string result
  817. char hash[2 * sizeof(digest) + 1];
  818. for (size_t i = 0; i < sizeof(digest); ++i) {
  819. snprintf(hash + (2 * i), 3, "%02x", (int)(digest[i]));
  820. }
  821. result = CFStringCreateWithCString(kCFAllocatorDefault,(const char *)hash,kCFStringEncodingUTF8);
  822. done:
  823. if (readStream) {
  824. CFReadStreamClose(readStream);
  825. CFRelease(readStream);
  826. }
  827. if (fileURL) {
  828. CFRelease(fileURL);
  829. }
  830. return result;
  831. }
  832. + (BOOL)fileExistsAtPath:(NSString *)path {
  833. NSFileManager *fm = [NSFileManager defaultManager];
  834. return [fm fileExistsAtPath:path];
  835. return NO;
  836. }
  837. + (NSString *)htmlForVideo:(NSString*) iframeCode template:(NSString*) path
  838. {
  839. if(path==nil)
  840. path=[[NSBundle mainBundle] pathForResource:@"photostack_video" ofType:@"html"];
  841. NSString* tempate = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  842. if(tempate==nil)
  843. return @"";
  844. // NSData *imageData = UIImageJPEGRepresentation(image,1.0);
  845. // NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[imageData base64Encoding]];
  846. // imageSource=[NSString stringWithFormat:@"<img src = \"%@\" />", imageSource];
  847. tempate= [tempate stringByReplacingOccurrencesOfString:@"##replacement##" withString:iframeCode];
  848. return tempate;
  849. }
  850. + (NSString *)htmlForImage:(UIImage *)image template:(NSString*) path
  851. {
  852. if(path==nil)
  853. path=[[NSBundle mainBundle] pathForResource:@"photostack_image" ofType:@"html"];
  854. NSString* tempate = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  855. if(tempate==nil)
  856. return @"";
  857. NSData *imageData = UIImageJPEGRepresentation(image,1.0);
  858. // NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[imageData base64Encoding]];
  859. NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];
  860. imageSource=[NSString stringWithFormat:@"<img src = \"%@\" />", imageSource];
  861. tempate= [tempate stringByReplacingOccurrencesOfString:@"##replacement##" withString:imageSource];
  862. return tempate;
  863. }
  864. + (nullable NSString *)md5:(nullable NSString *)str {
  865. if (!str) return nil;
  866. const char *cStr = str.UTF8String;
  867. unsigned char result[CC_MD5_DIGEST_LENGTH];
  868. CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
  869. NSMutableString *md5Str = [NSMutableString string];
  870. for (int i = 0; i < CC_MD5_DIGEST_LENGTH; ++i) {
  871. [md5Str appendFormat:@"%02x", result[i]];
  872. }
  873. return md5Str;
  874. }
  875. + (void)ra_showAlertTitle:(NSString *)title message:(NSString *)msg withViewController:(UIViewController *)vc {
  876. if (vc) {
  877. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
  878. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  879. }];
  880. [alertVC addAction:okAction];
  881. [vc presentViewController:alertVC animated:YES completion:nil];
  882. NSLog(@"show alerttitle alert %p",alertVC);
  883. }
  884. }
  885. + (CGSize)sizeWithFont:(NSString*)string font:(UIFont *)font constrainedToSize:(CGSize)maxsize lineBreakMode:(NSLineBreakMode)lineBreakMode
  886. {
  887. if(string.length==0)
  888. return CGSizeZero;
  889. // Let's make an NSAttributedString first
  890. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  891. //Add LineBreakMode
  892. NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
  893. [paragraphStyle setLineBreakMode:lineBreakMode];
  894. [attributedString setAttributes:@{NSParagraphStyleAttributeName:paragraphStyle} range:NSMakeRange(0, attributedString.length)];
  895. // Add Font
  896. [attributedString setAttributes:@{NSFontAttributeName:font} range:NSMakeRange(0, attributedString.length)];
  897. //Now let's make the Bounding Rect
  898. CGSize expectedSize = [attributedString boundingRectWithSize:maxsize options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
  899. return expectedSize;
  900. }
  901. + (BOOL) validateEmail:(NSString *)email
  902. {
  903. NSString *regex1 = @"\\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,4}\\z";
  904. NSString *regex2 = @"^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*";
  905. NSPredicate *test1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex1];
  906. NSPredicate *test2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex2];
  907. return [test1 evaluateWithObject:email] && [test2 evaluateWithObject:email];
  908. }
  909. + (BOOL)checkPassword:(NSString *) password
  910. {
  911. NSString *pattern = @"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{8,16}";
  912. // NSString *pattern1 = @"^(?=.*)(?=.*[a-z])(?=.*[~!@#$%^&*:;,.=?$\x22]).{8,16}$";
  913. NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
  914. // NSPredicate *pred1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern1];
  915. BOOL isMatch = [pred evaluateWithObject:password];//||[pred evaluateWithObject:password];
  916. return isMatch;
  917. }
  918. + (UIViewController *)getCurrentVC
  919. {
  920. UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
  921. UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
  922. return currentVC;
  923. }
  924. + (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC
  925. {
  926. UIViewController *currentVC;
  927. if ([rootVC presentedViewController]) {
  928. // 视图是被presented出来的
  929. rootVC = [rootVC presentedViewController];
  930. }
  931. if ([rootVC isKindOfClass:[UITabBarController class]]) {
  932. // 根视图为UITabBarController
  933. currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
  934. } else if ([rootVC isKindOfClass:[UINavigationController class]]){
  935. // 根视图为UINavigationController
  936. currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
  937. } else {
  938. // 根视图为非导航类
  939. currentVC = rootVC;
  940. }
  941. return currentVC;
  942. }
  943. @end