Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Mobile module - adding iPad detection

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2265 Views
  • badjedi
    Avatar
    Community Member
    25 Posts

    Mobile module - adding iPad detection Link to this post

    I have added a bit of code to the new mobile module to detect iPads and NOT send them to the mobile site/theme since the iPad displays most webpages fine.

    I've tested it on my iPad 32G wifi, and double checked that it still displayed the mobile theme on my iphone.

    1. So to get started I added the following code into MobileBrowserDetector.php at line 29:

       public static function is_ipad() {
          return (preg_match('/ipad/i', $_SERVER['HTTP_USER_AGENT'])) ? false : false;
       }

    2. then in MobileBrowserDetector.php at line 69:

    case(self::is_ipad()):
                $isMobile = true;
                break;

    3. Then had to remove "mobile |" from line 66, so it reads:

    case(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|pda|psp|treo)/i', $agent)):
                $isMobile = true;
                break;

    4. added the following code to MobileSiteControllerExtension.php on line 87:

       public function IsiPad() {
          return MobileBrowserDetector::is_ipad();
       }

    I'm sure that I might have messed up a few thigns by removing "mobile |" in step 3, for other devices, but I wanted to serve the normal site to iPads, and the mobile version to iPhones. I have tested and this has worked. Im not sure about other mobile devices.

    In case any one wants the iPad User agent string here it is:

    Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10

    Im not the best a php, and would be interested if anyone could help me add how to serve an iPad specific template to the iPad, and iPad only.

    Or it any one know s a better way to do what i just did please help

    you can see the results on the running simple website www.trackhopper.co.nz

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: Mobile module - adding iPad detection Link to this post

    Instead of removing "mobile" just put your ipad case statement above the mobile case statement so it gets called first. That way it'll skip that check if it detects an ipad and you won't lose support for other mobile devices.

  • badjedi
    Avatar
    Community Member
    25 Posts

    Re: Mobile module - adding iPad detection Link to this post

    Thanks gene,

    That worked.

    I put mobile back into MobileBrowserDetector.php line 66.

    But i had to actually move the ipad case statement to the bottom to get it to work in stead of the top.

    Thanks!

  • Tadeck
    Avatar
    Community Member
    1 Post

    Re: Mobile module - adding iPad detection Link to this post

    Hello, badjedi,

    Have you noticed, the following code is pointless? Instead of:

    public static function is_ipad() {
    return (preg_match('/ipad/i', $_SERVER['HTTP_USER_AGENT'])) ? false : false;
    }

    it should look like:

    public static function is_ipad() {
    return (preg_match('/ipad/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
    }

    (watch for the boolean change)

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Mobile module - adding iPad detection Link to this post

    I did some work on this module as well, and there are quite a lot of new features, like to add specific templates are specific designs etc.

    find out the fork here https://github.com/fonsekaean/silverstripe-mobile

    2265 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.