您可以使用以下任何示例来解决。
使用 diapatch_async
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:urlString];
});
使用性能选择器
- (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]];
}
使用 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]];
}