OpenUrl freezes app for over 10 seconds
[[UIApplication sharedApplication] openURL:urlString] 메소드 사용시 10초 이상 프리징 되는 현상이 발생함.
딜레이도 아니고 프리징.. 10초 정도 아무것도 안됨..
아래 세 가지 방법으로 해결..
어쨌든 해결되는 원리는 같겠지만 ㅋㅋ
#1. 메인 쓰레드 호출해서 실행
dispatch_async(dispatch_get_main_queue(), ^{ [[UIApplication sharedApplication] openURL:urlString]; });
#2. performSelector 메소드 실행
- (void)applicationDidBecomeActive:(UIApplication *)application { ... //hangs for 10 seconds //[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]]; //Fix: use threads! [self performSelector:@selector(redirectToURL:) withObject:url afterDelay:0.0]; ... } - (void)redirectToURL:(NSString *)url { [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]]; }
#3. NSThread 이용
- (void)applicationDidBecomeActive:(UIApplication *)application { ... //hangs for 10 seconds //[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]]; //Fix: use threads! [NSThread detachNewThreadSelector:@selector(openBrowserInBackground:) toTarget:self withObject:url]; ... } - (void)openBrowserInBackground:(NSString *)url { [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]]; }
[출처] http://stackoverflow.com/questions/19356488/openurl-freezes-app-for-over-10-seconds