kenwarner
kenwarner

Reputation: 29120

browser detection for iPhone 4

Is there a reliable way to detect iPhone 4 (as opposed to iPhone 3 or iPad)? extra points if you can do it with .browser files or WURFL

Upvotes: 1

Views: 2126

Answers (2)

Spudley
Spudley

Reputation: 168655

You haven't specified why you want to do browser detection, but the standard reason is because certain browsers or versions don't support a given feature that you want to use.

If that's the case, have you considered feature detection instead? A tool like Modernizr should be able to help with that.

[EDIT] If all you want to do is measure the screen resolution, you can use screen.width and screen.height in Javascript.

Hope that helps.

Upvotes: 0

Mrchief
Mrchief

Reputation: 76198

Checkout 51degress.mobi on codeplex. It is active and I have had good experience with it in past.

There is another codeplex project too but its no longer active: Mobile Device Browser File

To detect iPhone 4 specifically, use:

string strUserAgent = Request.UserAgent.ToString().ToLower();
if (Request.Browser.IsMobileDevice == true && strUserAgent.Contains("iphone OS 4")) 
{
    // code for iPhone 4
}

iPhone user agents look like (n stands for version like 4_3_3)

Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_n_n like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7

Upvotes: 5

Related Questions