Search code examples
asp.nethtmliphone-4browser-detection

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


Solution

  • 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