serbanghita / Mobile-Detect

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
http://mobiledetect.net
MIT License
10.52k stars 2.67k forks source link

New iPad OS detected as computer #917

Open foRsxs opened 1 year ago

foRsxs commented 1 year ago

Hello! New iPad OS detected as computer. In new version Apple use core like on Mac

webdesignweisshart commented 1 year ago

Same with Microsoft Surface Go Win 11. Also detected as computer.

aaronsummers commented 1 year ago

Hello! New iPad OS detected as computer. In new version Apple use core like on Mac

I created a hacky way to detect the new iPad iOS. I found that the version number on a Mac contains a dot (.) and the version number on an iPad contains an underscore(_).

I'm just checking the version for an underscore and setting a global variable.

This may be of use to someone else.

(As a side note: I'm actually using this to set a session cookie within my own site rather than a global variable. But that code is out of scope for this reply.)

       /**
     * HACKY WAY TO SEE IF WE'RE ON A IOS DEVICE 
     ** Checking the user agent
     ** Separate the content between the brackets returned by the user agent 
     ** Create an array of the mobile device os separated by semicolon
     ** Check for an underscore which is only used by iOS within the version number 
     ** @example  '10.1' (Mac OS) / '10_1' (iOS)
     */
    $mobile_detect = new \Detection\MobileDetect;
    $userAgent     = $mobile_detect->userAgent;
    $explode       = explode( '(', $userAgent );
    preg_match( '#\((.*?)\)#', $userAgent, $match );
    $current_os        = $match[1] ?? '';
    $current_os_array  = explode( '; ', $current_os );
    $mobile_os_version = ( str_contains( $current_os_array[1], '_' ) && str_contains( $current_os_array[1], 'OS X' ) );

    // Create the global variable...
    $GLOBALS['is_new_apple_tablet'] = $mobile_os_version; // @return boolean true || false
seasoftjapan commented 3 months ago

@aaronsummers Your idea is very interesting. But is it really discernible?

However, according to the following article, both OSes seem to use “_”. https://www.bit-hive.com/articles/20190820

[Safari on iPad + iPadOS13(デスクトップ用Webサイトを表示:On設定時)] Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15

[Safari on macOS Mojave] Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Safari/605.1.15

I don't have that device so I can't verify it.