我有一个应用程序,它只需启动带有链接的浏览器并自行关闭。 这是代码:
#import "ViewController.h"
@implementation ViewController
-(void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor= [UIColor cyanColor];
mLinkview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[mLinkview setDelegate:self];
NSURL *url = [NSURL URLWithString:@"http://www.mediklean.com"];
[[UIApplication sharedApplication] openURL:url];
exit(0);
[self.view addSubview:mLinkview];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
问题是,启动浏览器需要很长时间,比如 10 秒
。如果这是由代码或其他原因引起的问题,有人可以提供帮助吗?
最佳答案
不要使用
[[UIApplication sharedApplication] openURL:url];
而是做这样的事情:
NSURL *url = [NSURL URLWithString:@"http://www.mediklean.com"];];
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[webView loadRequest:request];
使用 webView 加载请求。
Apple 明确禁止您在自己的应用程序中调用 exit。终止由 iOS 处理。
关于ios - 简单的浏览器启动需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20857129/