0

Yeah, I could detect it in Objective C and then modify the html accordingly. But can I put it directly into the html? So if the user clicks the link on an iPhone (or iPod Touch), they go to

http://link-for-iphone-users.com

But if they click the same link on an iPad, they instead go to

http://link-for-ipad-users.com

EDIT: To clarify, the html in question ships with the app. If the html detection is a mess, I'll just go the UIDevice route.

William Jockusch
  • 26,513
  • 49
  • 182
  • 323
  • 1
    Don't you have a separate build for the iPad ? If you choose iPad in your build I believe you can provide the link just for iPad in it. – Legolas Dec 27 '11 at 04:37
  • Most people use a universal app build, so it's most likely the same code base with different interface files. – Jack Lawrence Dec 27 '11 at 04:57

4 Answers4

2

It would be simplist to just do the detection on the device using the [UIDevice currentDevice].model call described in Jack Lawrence's answer.

If you really want to use one URL though, you could handle the detection on the server-side by looking at the user agent string in the HTTP headers of the request that the user makes to your one url. Requests from the iPad look something like this:

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

Note the "iPad" designation.

You could write your website to check the user agent for the device information and then redirect as needed.

Hivebrain
  • 784
  • 1
  • 8
  • 11
1

I'm not sure what you're trying to do here, but I'm going to assume the HTML is loaded externally to the device.

If this is the case, you can get the user agent string and set the link appropriately using javascript (or server-side, as very much well said by Hivebrain).

The user agent string for an iPad might look something like this:

Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10

The iPhone one might look like this:

HTTP_USER_AGENT=Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3

You can get the user agent string using navigator.userAgent. Having this, should be easy to write a simple if condition that check's the user agent and sets the link accordingly.

On the other hand, if the HTML isn't loaded externally to the device, I personally see no point on putting the condition right on the HTML.

Some references:

http://www.htmlgoodies.com/beyond/webmaster/toolbox/article.php/3888106/How-Can-I-Detect-the-iPhone--iPads-User-Agent.htm

What is the iPad user agent?

http://www.w3schools.com/jsref/prop_nav_useragent.asp

Community
  • 1
  • 1
Telmo Marques
  • 5,066
  • 1
  • 24
  • 34
0

Check out the UIDevice class docs.

NSString *deviceType = [UIDevice currentDevice].model;

if([deviceType isEqualToString:@"iPhone"])
    // set url to an iPhone url
Jack Lawrence
  • 10,664
  • 1
  • 47
  • 61
0

Whether you are on an iPhone or a iPod Touch:

UIDevice *device = [UIDevice currentDevice];
NSString *systemName = [device systemName];

To detect the version of the OS:

UIDevice *device = [UIDevice currentDevice];
NSString *systemVersion = [device systemVersion];
Legolas
  • 12,145
  • 12
  • 79
  • 132