2012-12-16 52 views
19

我有一個應用程序,它將用戶ID和代碼存儲在NSUSERDEFAULTS中我需要使用這些值才能讓UIWebView訪問以下URL:www.mywebsite.com/check.php?id=(idhere )& code =(idhere)。UIWebView加載帶參數的URL

我看過其他一些話題,但目前爲止似乎沒有任何幫助。

我是該語言的新手,所以感謝您的耐心等待。

傑克布朗。

回答

10
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 

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


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

所以你的URL字符串會,

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

其中userIdkey是您用來存儲userId和codeKey的密鑰,您用於存儲代碼 –

+0

非常感謝您,我是一名新開發人員,這很容易理解!再次感謝:)所有工作:) –

+0

米gald它幫助你..好運..:)... –

38

最簡單的形式:

- (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]; 
} 
+0

哪裏abouts我指向位於NSUserDefaults的中的變量? –