0

I tried to open multiple URLs in a row in a single UIWebView but it only open the last URL (last member of the macArray).

- (IBAction)openURL:(id)sender {

    macArray = [NSArray arrayWithObjects:@"XX:XX:XX:XX:XX:XX", @"XX:XX:XX:XX:XX:XX", nil];

    NSString *part1URL = @"http://myurl?mac=";
    NSString *part2URL = @"&dothis";

    for (int i = 0; i < macArray.count; i++) {
        NSLog(@"%@", macArray[i]);

        NSString *mac = [macArray objectAtIndex:i];

        NSString *beginURL = [part1URL stringByAppendingString:mac];
        NSString *URL = [beginURL stringByAppendingString:part2URL];

        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
        [webView loadRequest:request];
    }
}

Does anyone have any idea? Thank you in advance and have a good day / night.

2
  • 1
    Try "NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [NSURLConnection sendSynchronousRequest:requestObj returningResponse:&response error:&error];" instead of "[webView loadRequest:request];"
    – Kumar KL
    Commented Jun 6, 2013 at 12:05
  • With NSError *error; & NSURLResponse *response; it works pretty well thank you Commented Jun 6, 2013 at 12:49

2 Answers 2

6

You can't open more than one URL in a web view!

Why not use more than one web view?


EDIT : You're doing what?

OK, a UIWebView is very much for rendering and displaying a web page. If you want to just send a web request, what's wrong with NSURLConnection or a library like AFNetworking?

3
  • It's a hidden web view. I just use it to send my order (who is contained in the URL). Commented Jun 6, 2013 at 10:22
  • Wat?? :O You're doing what?
    – pbibergal
    Commented Jun 6, 2013 at 10:23
  • 2
    UIWebView is an UI element and it's only purpose is to be shown on the screen. If you want to send data find another way.
    – pbibergal
    Commented Jun 6, 2013 at 10:25
0

I add this to my program:

NSError *error;
NSURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

and delete that:

[webView loadRequest:request];
2
  • FYI: sendSynchronousRequest will block the thread that sends it - you probably don't want to do that on the main thread because the UI will freeze! Commented Jun 6, 2013 at 13:18
  • @deanWombourne : So what do you suggest? Commented Jun 6, 2013 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.