0

I have an app which simply launches browser with a link and closes itself. Here is the code:

#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

The problem is , it's taking very long time , like 10 seconds before launching the browser. Can anyone help if this is a problem caused by code or something else?.

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
ZooZ
  • 309
  • 5
  • 19

3 Answers3

2

Don't use

[[UIApplication sharedApplication] openURL:url]; 

Instead do something like this:

NSURL *url = [NSURL URLWithString:@"http://www.mediklean.com"];];

NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];

[webView loadRequest:request];

Use the webView to load the request.

Apple explicitly forbids you calling exit on your own application. Termination is handled by iOS.

Woodstock
  • 22,184
  • 15
  • 80
  • 118
  • What webview? She(he) doesn't have a webview in her(his) code. As such I don't think she(he) intends to use a webview, the intention seems to be to open the URL in an extrenal web browser. – Hugo Tunius Dec 31 '13 at 12:13
  • yes they do: mLinkview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; – Woodstock Dec 31 '13 at 12:14
  • Oh, my bad. I just looked for properties, sorry about that. – Hugo Tunius Dec 31 '13 at 12:15
1

The reason it takes so long to open the browser is most likely because the website specified is painfully slow. It took over 10 seconds to load using my computer. Try changing it to use google.com and see if it is still slow.

On another not you should call exit when developing for iOS see this question for further information.

Community
  • 1
  • 1
Hugo Tunius
  • 2,869
  • 24
  • 32
-1

Launch the browser in your viewDidAppear method. It will minimize your delay.

-(void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];
    NSURL *url = [NSURL URLWithString:@"http://www.mediklean.com"];
    [[UIApplication sharedApplication] openURL:url];
    exit(0);
}
Mani Kandan
  • 629
  • 4
  • 12