1

I'm getching content in a universal iOS app using:

NSString stringWithContentsOfURL: [ NSURL URLWithString: link ]

... does that send iPhone/iPad user's IP and User-Agent to the server from which its fetching content from?

I need it to send at least user-agent so I can detect whether its an iPhone or iPad and optimize the content accordingly.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
eozzy
  • 66,048
  • 104
  • 272
  • 428

1 Answers1

0

You can use the code below to make sure that the devices is sending an user agent by manually specifying which one to use.

Modified quote from: https://stackoverflow.com/a/1533032/716216

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
    NSString* userAgent = @"Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10";
    NSURL* url = [NSURL URLWithString:@"http://www.myWebSite.com/"];
    NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url]
                                    autorelease];
    [request setValue:userAgent forHTTPHeaderField:@"User-Agent"];

    NSURLResponse* response = nil;
    NSError* error = nil;
    NSData* data = [NSURLConnection sendSynchronousRequest:request
                                         returningResponse:&response
                                                     error:&error];
}

NOTE: The sample user agent I've listed may be dated, and you MAY need to find a newer one.

Community
  • 1
  • 1
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281