agent icon indicating copy to clipboard operation
agent copied to clipboard

isMobile & isTablet both return true

Open jamesmills opened this issue 7 years ago • 5 comments

$agent->isMobile();
$agent->isTablet();

When we have tested this we have found that if the device user agent is iPad then when you call isMobile it is returning true and when you call isTablet is also returns true.

So when we do

if ($agent->isMobile()) {
    return 'Mobile';
} elseif ($agent->isTablet()) {
    return 'Tablet';
} elseif ($agent->isDesktop()) {
    return 'Desktop';
}

if it's, for example, iPad or iPhone it will always return 'Mobile'.

Is this expected behaviour?

jamesmills avatar Mar 27 '17 08:03 jamesmills

OK, turns out it always returns tablet as mobile. So you have to switch the logic to

if ($agent->isTablet()) {
    return 'Tablet';
} elseif ($agent->isMobile()) {
    return 'Mobile';
} elseif ($agent->isDesktop()) {
    return 'Desktop';
}

Hope this helps someone.

jamesmills avatar Mar 27 '17 10:03 jamesmills

it's intended that tablet will return true in function isMobile, because tablet is mobile device, not a stationary.

from code examples you can see:

isMobile() && !$detect->isTablet()) { // Your code here. }

evilangelmd avatar Mar 27 '17 10:03 evilangelmd

Have to be mentioned in the docs.

HosMercury avatar May 17 '17 07:05 HosMercury

isMobile() checks if the device is considered mobile (movable around), if you want to check if it's a phone, use isPhone().

Saracevas avatar Jul 17 '18 18:07 Saracevas

I would have thought many would want to know if the device is tablet, phone or desktop. Would it be helpful to have something in the package to do something like this?

$device_type = $agent->deviceType();

if ($agent->isTablet()) {
    return 'Tablet';
} elseif ($agent->isPhone()) {
    return 'Phone';
} elseif ($agent->isDesktop()) {
    return 'Desktop';
}

jamesmills avatar Jul 22 '18 08:07 jamesmills