I have a WebGL app that uses a JSLIB file that checks if my app is running on mobile to change the control scheme from keyboard/mouse to touch. Everything seems to work properly except for iPads, which gets detected as non-mobile for some reason.
It seems iPads are a tricky beast. This (found here) worked for me (tested on my iPad):
.jslib file (in Assets/Plugins/WebGL)
var kamgamDeviceDetector = {
KamgamIsMobilePlatform : function()
{
var userAgent = navigator.userAgent;
isMobile = (
/\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(userAgent) ||
/\b(Android|Windows Phone|iPad|iPod)\b/i.test(userAgent) ||
// iPad on iOS 13 detection
(userAgent.includes("Mac") && "ontouchend" in document)
);
return isMobile;
}
};
mergeInto(LibraryManager.library, kamgamDeviceDetector);
Unity c# Code:
using System.Runtime.InteropServices;
using UnityEngine;
namespace Kamgam
{
public static class MobileDeviceDetector
{
[DllImport("__Internal")]
public static extern bool KamgamIsMobilePlatform();
public static bool IsMobileBrowser()
{
#if UNITY_EDITOR
return false; // value to return in Play Mode (in the editor)
#elif UNITY_WEBGL
return KamgamIsMobilePlatform(); // value based on the current browser
#else
return Application.isMobilePlatform;
#endif
}
}
}
I am not sure if it reports false positives on MACs with touch display. AFAIK there are no official Apple touch monitors or laptops. Yet, if anyone can test that please let me know the results.