【问题标题】:UIWebView Load URL with parametersUIWebView 加载带有参数的 URL
【发布时间】:2012-12-03 15:36:32
【问题描述】:

我有一个将用户 ID 和代码存储在 NSUSERDEFAULTS 中的应用程序我需要使用这些值才能让 UIWebView 访问 url:www.mywebsite.com/check.php?id=(idhere)&code=(idhere )。

我查看了其他一些主题,但到目前为止似乎没有任何帮助。

我是这种语言的新手,所以感谢您的耐心等待。

杰克·布朗。

【问题讨论】:

    标签: iphone objective-c url uiwebview nsuserdefaults


    【解决方案1】:

    最简单的形式:

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

    【讨论】:

    • 我应该在哪里指向nsuserdefaults中的变量?
    【解决方案2】:
    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];
    

    【讨论】:

    • 其中 userIdkey 是您用来存储 userId 的密钥,codeKey 是您用来存储代码的密钥
    • 非常感谢,我是一名新开发人员,这很容易理解!再次感谢 :) 一切正常 :)
    猜你喜欢
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    相关资源
    最近更新 更多