UIWebView Load URL with parameters

Jack Brown picture Jack Brown · Dec 16, 2012 · Viewed 34.9k times · Source

I have an application that stores the user ID and code in NSUSERDEFAULTS I need to use these values in order to get UIWebView to visit url: www.mywebsite.com/check.php?id=(idhere)&code=(idhere).

I have looked at some other topics but nothing has seemed to help so far.

I'm new to this language so thanks for your patience.

Jack Brown.

Answer

Karthik picture Karthik · Dec 16, 2012

Simplest form:

- (void) viewDidLoad 
{    
    [super viewDidLoad];

    UIWebView *webView = [UIWebView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:webView];
    NSString *url = @"http://google.com?get=something&...";
    NSURL *nsUrl = [NSURL URLWithString:url];
    NSURLRequest *request = [NSURLRequest requestWithURL:nsUrl cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];

    [webView loadRequest:request];
}