How do I check if the useragent is an ipad or iphone?

前端 未结 9 2554
礼貌的吻别
礼貌的吻别 2020-12-09 14:42

I\'m using a C# asp.net website.

How can I check if the user using ipad or iphone? How can I check the platform?

For example, if the user enter the websi

9条回答
  •  孤城傲影
    2020-12-09 15:36

    Be careful of Windows phones! For some weird reason lots of Windows phones say "like iPhone" in the user agent. So you want to check:

    public bool IsIPhone
    {
        get
        {
            if (!UserAgent.ToUpper().Contains("LIKE IPHONE"))
            {
                return UserAgent.ToUpper().Contains("IPHONE");
            }
            return false;
        }
    }
    

    Example Windows phone user agent (from Lumia 735):

    "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 735) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537"

提交回复
热议问题