TCUtil.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. //
  2. // TCUtil.m
  3. // TCLVBIMDemo
  4. //
  5. // Created by felixlin on 16/8/2.
  6. // Copyright © 2016年 tencent. All rights reserved.
  7. //
  8. #import "TCUtil.h"
  9. //#import "MCTip.h"
  10. #import "NSData+Common.h"
  11. #import "NSString+Common.h"
  12. #import <mach/mach.h>
  13. #import <Accelerate/Accelerate.h>
  14. #import <mach/mach.h>
  15. #import <sys/types.h>
  16. #import <sys/sysctl.h>
  17. #import "TCUserInfoModel.h"
  18. //#import "TCLoginParam.h"
  19. #import "AFNetworking.h"
  20. static BOOL ShouldReport = YES;
  21. @implementation TCUtil
  22. #ifndef DEBUG
  23. + (void)load {
  24. NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
  25. if ([bundleID isEqualToString:@"com.tencent.liteav.ugc"]) {
  26. ShouldReport = YES;
  27. }
  28. }
  29. #endif
  30. + (NSData *)dictionary2JsonData:(NSDictionary *)dict
  31. {
  32. // 转成Json数据
  33. if ([NSJSONSerialization isValidJSONObject:dict])
  34. {
  35. NSError *error = nil;
  36. NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
  37. if(error)
  38. {
  39. DebugLog(@"[%@] Post Json Error", [self class]);
  40. }
  41. return data;
  42. }
  43. else
  44. {
  45. DebugLog(@"[%@] Post Json is not valid", [self class]);
  46. }
  47. return nil;
  48. }
  49. + (NSDictionary *)jsonData2Dictionary:(NSString *)jsonData
  50. {
  51. if (jsonData == nil) {
  52. return nil;
  53. }
  54. NSData *data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
  55. NSError *err = nil;
  56. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&err];
  57. if (err) {
  58. DebugLog(@"Json parse failed: %@", jsonData);
  59. return nil;
  60. }
  61. return dic;
  62. }
  63. + (NSString *)getFileCachePath:(NSString *)fileName
  64. {
  65. if (nil == fileName)
  66. {
  67. return nil;
  68. }
  69. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  70. NSString *cacheDirectory = [paths objectAtIndex:0];
  71. NSString *fileFullPath = [cacheDirectory stringByAppendingPathComponent:fileName];
  72. return fileFullPath;
  73. }
  74. +(void) removeCacheFile:(NSString*)filePath
  75. {
  76. NSError * error;
  77. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath] == YES) {
  78. [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
  79. }
  80. }
  81. //通过分别计算中文和其他字符来计算长度
  82. + (NSUInteger)getContentLength:(NSString*)content
  83. {
  84. size_t length = 0;
  85. for (int i = 0; i < [content length]; i++)
  86. {
  87. unichar ch = [content characterAtIndex:i];
  88. if (0x4e00 < ch && ch < 0x9fff)
  89. {
  90. length += 2;
  91. }
  92. else
  93. {
  94. length++;
  95. }
  96. }
  97. return length;
  98. }
  99. + (void)asyncSendHttpRequest:(NSString*)command token:(NSString*)token params:(NSDictionary*)params handler:(void (^)(int resultCode, NSString* message, NSDictionary* resultDict))handler
  100. {
  101. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  102. // NSData* data = [TCUtil dictionary2JsonData:params];
  103. // if (data == nil)
  104. // {
  105. // DebugLog(ASLocalizedString(@"sendHttpRequest failed,参数转成json格式失败"));
  106. // dispatch_async(dispatch_get_main_queue(), ^{
  107. // handler(kError_ConvertJsonFailed, ASLocalizedString(@"参数错误"), nil);
  108. // });
  109. // return;
  110. // }
  111. //
  112. // NSString* urlString = [kHttpServerAddr stringByAppendingPathComponent:command];
  113. // NSMutableString *strUrl = [[NSMutableString alloc] initWithString:urlString];
  114. //
  115. // NSURL *URL = [NSURL URLWithString:strUrl];
  116. // NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
  117. //
  118. // if (data)
  119. // {
  120. // [request setValue:[NSString stringWithFormat:@"%ld",(long)[data length]] forHTTPHeaderField:@"Content-Length"];
  121. // [request setHTTPMethod:@"POST"];
  122. // [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
  123. // [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
  124. // if (token.length > 0) {
  125. // NSString* sig = [[NSString stringWithFormat:@"%@%@", token, data.md5Hash] md5];
  126. // [request setValue:sig forHTTPHeaderField:@"Liteav-Sig"];
  127. // }
  128. // [request setHTTPBody:data];
  129. // }
  130. //
  131. // [request setTimeoutInterval:kHttpTimeout];
  132. //
  133. //
  134. // NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  135. // if (error != nil)
  136. // {
  137. // DebugLog(@"internalSendRequest failed,NSURLSessionDataTask return error code:%d, des:%@", [error code], [error description]);
  138. // dispatch_async(dispatch_get_main_queue(), ^{
  139. // handler(kError_HttpError, ASLocalizedString(@"服务请求失败"), nil);
  140. // });
  141. // }
  142. // else
  143. // {
  144. // NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  145. // NSDictionary* resultDict = [TCUtil jsonData2Dictionary:responseString];
  146. // int errCode = -1;
  147. // NSString* message = @"";
  148. // NSDictionary* dataDict = nil;
  149. // if (resultDict)
  150. // {
  151. // if (resultDict[@"code"]) {
  152. // errCode = [resultDict[@"code"] intValue];
  153. // }
  154. //
  155. // if (resultDict[@"message"]) {
  156. // message = resultDict[@"message"];
  157. // }
  158. //
  159. // if (200 == errCode && resultDict[@"data"])
  160. // {
  161. // dataDict = resultDict[@"data"];
  162. // }
  163. // }
  164. // dispatch_async(dispatch_get_main_queue(), ^{
  165. // handler(errCode, message, dataDict);
  166. // });
  167. // }
  168. // }];
  169. //
  170. // [task resume];
  171. // });
  172. }
  173. + (void)downloadVideo:(NSString *)videoUrl cachePath:(NSString *)cachePath process:(void(^)(CGFloat process))processHandler complete:(void(^)(NSString *videoPath))completeHandler
  174. {
  175. //初始化manager对象:
  176. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  177. AFURLSessionManager *manager = [[AFURLSessionManager alloc]initWithSessionConfiguration:configuration];
  178. NSURL *url = [NSURL URLWithString:videoUrl];
  179. //开始请求数据
  180. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  181. //创建downloadtask
  182. NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
  183. dispatch_async(dispatch_get_main_queue(), ^{
  184. processHandler((float)downloadProgress.completedUnitCount / (float)downloadProgress.totalUnitCount);
  185. });
  186. } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
  187. if (cachePath == nil){
  188. NSURL *documentDirectoryURL = [[NSFileManager defaultManager]URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:url create:NO error:nil];
  189. return [documentDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
  190. }else{
  191. return [NSURL fileURLWithPath:cachePath];
  192. }
  193. } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
  194. dispatch_async(dispatch_get_main_queue(), ^{
  195. completeHandler(filePath.path);
  196. });
  197. }];
  198. //开始下载
  199. [downloadTask resume];
  200. }
  201. + (void)asyncSendHttpRequest:(NSString*)command params:(NSDictionary*)params handler:(void (^)(int resultCode, NSString* message, NSDictionary* resultDict))handler
  202. {
  203. [self asyncSendHttpRequest:command token:nil params:params handler:handler];
  204. }
  205. + (void)asyncSendHttpRequest:(NSDictionary*)param handler:(void (^)(int result, NSDictionary* resultDict))handler
  206. {
  207. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  208. NSData* data = [TCUtil dictionary2JsonData:param];
  209. if (data == nil)
  210. {
  211. DebugLog(@"sendHttpRequest failed,参数转成json格式失败");
  212. dispatch_async(dispatch_get_main_queue(), ^{
  213. handler(kError_ConvertJsonFailed, nil);
  214. });
  215. return;
  216. }
  217. NSMutableString *strUrl = [[NSMutableString alloc] initWithString:kHttpServerAddr];
  218. NSURL *URL = [NSURL URLWithString:strUrl];
  219. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
  220. if (data)
  221. {
  222. [request setValue:[NSString stringWithFormat:@"%ld",(long)[data length]] forHTTPHeaderField:@"Content-Length"];
  223. [request setHTTPMethod:@"POST"];
  224. [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
  225. [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
  226. [request setHTTPBody:data];
  227. }
  228. [request setTimeoutInterval:kHttpTimeout];
  229. NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  230. if (error != nil)
  231. {
  232. DebugLog(@"internalSendRequest failed,NSURLSessionDataTask return error code:%d, des:%@", [error code], [error description]);
  233. dispatch_async(dispatch_get_main_queue(), ^{
  234. handler(kError_HttpError, nil);
  235. });
  236. }
  237. else
  238. {
  239. NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  240. NSDictionary* resultDict = [TCUtil jsonData2Dictionary:responseString];
  241. int errCode = -1;
  242. NSDictionary* dataDict = nil;
  243. if (resultDict)
  244. {
  245. if (resultDict[@"returnValue"])
  246. errCode = [resultDict[@"returnValue"] intValue];
  247. if (0 == errCode && resultDict[@"returnData"])
  248. {
  249. dataDict = resultDict[@"returnData"];
  250. }
  251. }
  252. dispatch_async(dispatch_get_main_queue(), ^{
  253. handler(errCode, dataDict);
  254. });
  255. }
  256. }];
  257. [task resume];
  258. });
  259. }
  260. + (void)report:(NSString *)type userName:(NSString *)userName code:(UInt64)code msg:(NSString *)msg;
  261. {
  262. // if(userName == nil){
  263. // userName = [TCLoginParam shareInstance].identifier;
  264. // }
  265. // NSMutableDictionary *param = [NSMutableDictionary dictionary];
  266. // // 过渡期间同时上报type和business保证报表数据可以连续展示
  267. // [param setObject:@"xiaoshipin" forKey:@"type"];
  268. // [param setObject:@"xiaoshipin" forKey:@"bussiness"];
  269. // [param setObject:@"ios" forKey:@"platform"];
  270. // [param setObject:userName == nil ? @"" : userName forKey:@"userName"];
  271. // [param setObject:type == nil ? @"" : type forKey:@"action"];
  272. // [param setObject:@(code) forKey:@"action_result_code"];
  273. // [param setObject:msg == nil ? @"" : msg forKey:@"action_result_msg"];
  274. // [self report:param handler:^(int resultCode, NSString *message) {
  275. // //to do
  276. // }];
  277. }
  278. + (void)report:(NSMutableDictionary *)param handler:(void (^)(int resultCode, NSString *message))handler;
  279. {
  280. if (!ShouldReport) {
  281. return;
  282. }
  283. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  284. NSData* data = [TCUtil dictionary2JsonData:param];
  285. if (data == nil)
  286. {
  287. DebugLog(@"sendHttpRequest failed,参数转成json格式失败");
  288. dispatch_async(dispatch_get_main_queue(), ^{
  289. handler(kError_ConvertJsonFailed, nil);
  290. });
  291. return;
  292. }
  293. NSMutableString *strUrl = [[NSMutableString alloc] initWithString:DEFAULT_ELK_HOST];
  294. NSURL *URL = [NSURL URLWithString:strUrl];
  295. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
  296. if (data)
  297. {
  298. [request setValue:[NSString stringWithFormat:@"%ld",(long)[data length]] forHTTPHeaderField:@"Content-Length"];
  299. [request setHTTPMethod:@"POST"];
  300. [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
  301. [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
  302. [request setHTTPBody:data];
  303. }
  304. [request setTimeoutInterval:kHttpTimeout];
  305. NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  306. if (error != nil)
  307. {
  308. DebugLog(@"internalSendRequest failed,NSURLSessionDataTask return error code:%d, des:%@", [error code], [error description]);
  309. dispatch_async(dispatch_get_main_queue(), ^{
  310. handler(kError_HttpError, nil);
  311. });
  312. }
  313. else
  314. {
  315. NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  316. dispatch_async(dispatch_get_main_queue(), ^{
  317. if ([responseString isEqualToString:@"ok"]) {
  318. handler(0, responseString);
  319. }else{
  320. handler(-1, responseString);
  321. }
  322. });
  323. }
  324. }];
  325. [task resume];
  326. });
  327. }
  328. + (NSString *)transImageURL2HttpsURL:(NSString *)httpURL
  329. {
  330. NSStringCheck(httpURL);
  331. NSString * httpsURL = httpURL;
  332. if ([httpURL hasPrefix:@"http:"]) {
  333. httpsURL = [httpURL stringByReplacingOccurrencesOfString:@"http:" withString:@"https:"];
  334. }else{
  335. httpsURL = [NSString stringWithFormat:@"https:%@",httpURL];
  336. }
  337. return httpsURL;
  338. }
  339. +(NSString*) getStreamIDByStreamUrl:(NSString*) strStreamUrl {
  340. if (strStreamUrl == nil || strStreamUrl.length == 0) {
  341. return nil;
  342. }
  343. strStreamUrl = [strStreamUrl lowercaseString];
  344. //推流地址格式:rtmp://8888.livepush.myqcloud.com/live/8888_test_12345_test?txSecret=aaaa&txTime=bbbb
  345. NSString * strLive = @"/live/";
  346. NSRange range = [strStreamUrl rangeOfString:strLive];
  347. if (range.location == NSNotFound) {
  348. return nil;
  349. }
  350. NSString * strSubString = [strStreamUrl substringFromIndex:range.location + range.length];
  351. NSArray * array = [strSubString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"?."]];
  352. if ([array count] > 0) {
  353. return [array objectAtIndex:0];
  354. }
  355. return nil;
  356. }
  357. //创建高斯模糊效果图片
  358. +(UIImage *)gsImage:(UIImage *)image withGsNumber:(CGFloat)blur
  359. {
  360. if (blur < 0.f || blur > 1.f) {
  361. blur = 0.5f;
  362. }
  363. int boxSize = (int)(blur * 40);
  364. boxSize = boxSize - (boxSize % 2) + 1;
  365. CGImageRef img = image.CGImage;
  366. vImage_Buffer inBuffer, outBuffer;
  367. vImage_Error error;
  368. void *pixelBuffer;
  369. //从CGImage中获取数据
  370. CGDataProviderRef inProvider = CGImageGetDataProvider(img);
  371. CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
  372. //设置从CGImage获取对象的属性
  373. inBuffer.width = CGImageGetWidth(img);
  374. inBuffer.height = CGImageGetHeight(img);
  375. inBuffer.rowBytes = CGImageGetBytesPerRow(img);
  376. inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);
  377. pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img));
  378. if(pixelBuffer == NULL)
  379. NSLog(@"No pixelbuffer");
  380. outBuffer.data = pixelBuffer;
  381. outBuffer.width = CGImageGetWidth(img);
  382. outBuffer.height = CGImageGetHeight(img);
  383. outBuffer.rowBytes = CGImageGetBytesPerRow(img);
  384. error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
  385. if (error) {
  386. NSLog(@"error from convolution %ld", error);
  387. }
  388. CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  389. CGContextRef ctx = CGBitmapContextCreate( outBuffer.data, outBuffer.width, outBuffer.height, 8, outBuffer.rowBytes, colorSpace, kCGImageAlphaNoneSkipLast);
  390. CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
  391. UIImage *returnImage = [UIImage imageWithCGImage:imageRef];
  392. //clean up
  393. CGContextRelease(ctx);
  394. CGColorSpaceRelease(colorSpace);
  395. free(pixelBuffer);
  396. CFRelease(inBitmapData);
  397. CGColorSpaceRelease(colorSpace);
  398. CGImageRelease(imageRef);
  399. return returnImage;
  400. }
  401. /**
  402. *缩放图片
  403. */
  404. +(UIImage*)scaleImage:(UIImage *)image scaleToSize:(CGSize)size{
  405. UIGraphicsBeginImageContext(size);
  406. [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
  407. UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  408. UIGraphicsEndImageContext();
  409. return scaledImage;
  410. }
  411. /**
  412. *裁剪图片
  413. */
  414. +(UIImage *)clipImage:(UIImage *)image inRect:(CGRect)rect{
  415. CGImageRef sourceImageRef = [image CGImage];
  416. CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
  417. UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
  418. CGImageRelease(newImageRef);
  419. return newImage;
  420. }
  421. + (float) heightForString:(UITextView *)textView andWidth:(float)width{
  422. CGSize sizeToFit = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
  423. return sizeToFit.height;
  424. }
  425. + (void) toastTip:(NSString*)toastInfo parentView:(UIView *)parentView
  426. {
  427. CGRect frameRC = [[UIScreen mainScreen] bounds];
  428. frameRC.origin.y = frameRC.size.height - 110;
  429. frameRC.size.height -= 110;
  430. __block UITextView * toastView = [[UITextView alloc] init];
  431. toastView.editable = NO;
  432. toastView.selectable = NO;
  433. frameRC.size.height = [self heightForString:toastView andWidth:frameRC.size.width];
  434. toastView.frame = frameRC;
  435. toastView.text = toastInfo;
  436. toastView.backgroundColor = [UIColor whiteColor];
  437. toastView.alpha = 0.5;
  438. [parentView addSubview:toastView];
  439. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC);
  440. dispatch_after(popTime, dispatch_get_main_queue(), ^(){
  441. [toastView removeFromSuperview];
  442. toastView = nil;
  443. });
  444. }
  445. +(BOOL)isSuitableMachine:(int)targetPlatNum
  446. {
  447. int mib[2] = {CTL_HW, HW_MACHINE};
  448. size_t len = 0;
  449. char* machine;
  450. sysctl(mib, 2, NULL, &len, NULL, 0);
  451. machine = (char*)malloc(len);
  452. sysctl(mib, 2, machine, &len, NULL, 0);
  453. NSString* platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
  454. free(machine);
  455. if ([platform length] > 6) {
  456. NSString * platNum = [NSString stringWithFormat:@"%C", [platform characterAtIndex: 6 ]];
  457. return ([platNum intValue] >= targetPlatNum);
  458. } else {
  459. return NO;
  460. }
  461. }
  462. +(NSDate *)timeToDate:(NSString *)timeStr
  463. {
  464. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  465. [formatter setDateStyle:NSDateFormatterMediumStyle];
  466. [formatter setTimeStyle:NSDateFormatterShortStyle];
  467. [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
  468. NSDate* date = [formatter dateFromString:timeStr];
  469. return date;
  470. }
  471. +(NSString *)dateToTime:(NSDate *)date
  472. {
  473. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  474. formatter.dateFormat = @"YYYY-MM-dd HH:mm:ss";
  475. NSString *time = [formatter stringFromDate:date];
  476. return time;
  477. }
  478. + (UIViewController*)currentViewController{
  479. UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController;
  480. while (true) {
  481. if ([vc isKindOfClass:[UINavigationController class]]) {
  482. vc = [(UINavigationController *)vc visibleViewController];
  483. } else if ([vc isKindOfClass:[UITabBarController class]]) {
  484. vc = [(UITabBarController *)vc selectedViewController];
  485. } else if (vc.presentedViewController) {
  486. vc = vc.presentedViewController;
  487. }else {
  488. break;
  489. }
  490. }
  491. return vc;
  492. }
  493. @end