Repository navigation
Description
Feature Request
Ionic version:
[x] 4.x
Describe the Feature Request
Platform detection in Ionic has worked fairly well for some time, but as the types of devices have diversified, I think it's time we rethink how we do platform detection. In particular, devices such as larger tablets are sometimes getting misclassified as desktop devices and some of the other detection methods are either a bit flimsy or hard to test.
Describe Preferred Solution
-
Discuss what should be considered
mobile. From what I've seen with a number of Android Tablets, they are not considered "mobile" (i.e. the word "mobile" is not in tablet user agents, but it is in phone user agents). We have a check calledisMobilethat returns true ifany-pointer: coarseinmatchMedia. Touch screens count as a coarse pointer, so touch screen laptops would be consideredmobilehere. -
Rewrite detection methods in a more "future-proof" way. I realize this is a difficult thing to do, but it would be good to write these methods in a way that will hold up over time. For example, the
isTabletmethod has not held up over time because we now have tablets that exceed the dimensions of what we test for (ex: iPad Pro). -
Add detection for desktop platforms. This is more for when we add desktop support, but it would be great to be able to detect
macOS,Windows,Linux, etc. Right now we haveisDesktopwhich wouldn't give that kind of information.
Describe Alternatives
I created a PR #17630 for better handling of tablet detection, but it's not perfect. The purpose of that PR was to add support for some of the larger tablets (iPad Pro, large Android tablets, etc).
Related Code
Check out: https://github.com/matthewhudson/current-device
It's not a perfect library, but I think it does a pretty good job of covering its bases in terms of platform detection. It probably does more than we really need, but I think it would be worthwhile to look at.
https://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent
https://webmasters.googleblog.com/2011/03/mo-better-to-also-detect-mobile-user.html
https://developers.chrome.com/multidevice/user-agent
Safari on iPadOS now serves up the macOS Safari user agent as part of its "desktop class browsing" change: https://medium.com/@pixelthing/safari-on-ipados13-a-web-devs-guide-c31b34236e61
Activity
liamdebeasi commentedon Mar 20, 2019
other issues to note:
any-pointer: Wrong platform detected with android 5.1, android 4.4 #17933alek-aleksandrov commentedon Mar 27, 2019
If it is relevant: for anyone using the current-device package to cover your bases instead of platform, it will conflict with the cordova plugin Device. Current-device and cordova Device both store information on the window.device property, so it causes issues if trying to use both. Warning to anyone who found this and perhaps if used to replace functionality.
rossholdway commentedon Aug 1, 2019
When running Ionic (latest version 4.7.1) iPadOS displays using the Android style :/
liamdebeasi commentedon Oct 18, 2019
After discussion with the team, we have decided to keep the overall platform detection as is. It's not realistically possible to account for 100% of Android devices, so we're going to opt to make smaller improvements as we find them rather than a massive overhaul.
Additionally, we have fixed the iPadOS bug in Ionic 4.9.1. Thanks!
ionitron-bot commentedon Nov 17, 2019
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.