RAUtils.m 39 KB

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