agent
agent copied to clipboard
isMobile & isTablet both return true
$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?
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.
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. }
Have to be mentioned in the docs.
isMobile() checks if the device is considered mobile (movable around), if you want to check if it's a phone, use isPhone().
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';
}