Jump to content

Module: Mobile Detect


justb3a
 Share

Recommended Posts

  • 1 year later...

I've just installed it on a PW 3.x site. 

It seems to detect Desktop correctly but I think it's returning an empty string for mobile. 
Haven't tested for Tablet but for my purposes I can live with this as I'm only interested in whether it's Desktop or not.

Will update if it can't detect Desktops correctly.

            if (wire(config)->mobileDetect->deviceType<>'desktop') {
				....
			}

 

Link to comment
Share on other sites

  • 2 weeks later...

I just wanted to update saying the module doesn't work.

The problem is that the actual PHP module it depends on, mobiledetect.php is using  $_SERVER['HTTP_USER_AGENT'] which is an outdated way of detecting devices from the server.  It failed on Safari where it couldn't distinguish whether you were using it from the Desktop or a mobile device.

(You could argue PHP is probably not the way to go, compared to JS but that's another post )

I must have tried every PHP based solution out there in the last couple of weeks.
The only thing that has worked for me is UserAgentInfo.

I'm posting an example here, in case some one wants to update this module :)
 

function IsMobile() {

    $ua =  UserAgentInfoPeer::getMy();
    $mobile = $ua->isMobile();
    return $mobile;
}

P/S  You will need to add a reference to this class (You may need to change the path to suit your code structure)

require_once(__DIR__.'/../vendor/UserAgentInfo/UserAgentInfoPeer.class.php');

and then you may need to configure UserAgentInfoConfig class if the caching mechanism (Redis by default) is not what you want. Just change the CACHE_CLASS_NAME to the class you want.

    //const CACHE_CLASS_NAME = 'UaiCachePhpredis';    //Not installed locally
    //const CACHE_CLASS_NAME = 'UaiCacheMemcached';   //Not installed on Provider
    //const CACHE_CLASS_NAME = 'UaiCacheAPC';         //Not installed on Provider
    const CACHE_CLASS_NAME =  'UaiCacheDebug';



FYI I had to go for the non cached version (UaiCacheDebug) because of the hosting solution we currently have (i.e. el cheapo solution)


 

Edited by FrancisChung
More info
Link to comment
Share on other sites

@FrancisChung Thanks a lot for your feedback and hints. The collaborators of the detection library are working on a new release.

Quote

Still working on 3.0.0 branch to provide you with device detection! We're really excited on this one! We would like to speed this up, but life and family gets in the way ;)

As soon as the release has been published, I'll update the module.

Link to comment
Share on other sites

  • 6 months later...
On 9.3.2017 at 3:03 PM, justb3a said:

@FrancisChung Thanks a lot for your feedback and hints. The collaborators of the detection library are working on a new release.

As soon as the release has been published, I'll update the module.

 

hmm … module didn't work (pw 3) but when i use the detection library and it works

// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
 
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
 
}

 

Link to comment
Share on other sites

  • 3 months later...
  • 8 months later...
  • 2 months later...

Hi. Nice module! Exactly what I was looking for to make my main nav-bar conditional (if desktop, hovering drops-down my menu but clicking goes to page, if tablet etc., clicking just drops-down). Perfect! Thanks.

echo "<li class='dropdown'><a href='". ($config->mobileDetect->deviceType == 'desktop' ? $child->url : '#') ."' data-hover='dropdown'>{$child->title}<b class='caret'></b></a>";

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...