Jack Brown
Jack Brown

Reputation: 580

UIWebView Load URL with parameters

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.

Upvotes: 20

Views: 35071

Answers (2)

Karthik
Karthik

Reputation: 1396

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];
}

Upvotes: 39

Vishal Singh
Vishal Singh

Reputation: 4490

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

NSString *userId= [prefs stringForKey:@"userIdkey"];


NSString *code= [prefs stringForKey:@"codeKey"];

and so your url string will be,

NSString *urlStr = [NSString stringWithFormat:@"http://www.mywebsite.com/check.php?id=%@&code=%@",userId,code];

Upvotes: 10

Related Questions