Detect iOS in OctoberCMS to differ the script or other resources loads

in the "code" section of the CMS page editor

put in below codes

function onStart()
{
 //Detect special conditions devices
 $iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
 $iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
 $iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
 $Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
 $webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");

 $this['isIos'] = false;

 //do something with this information
 if( $iPod || $iPhone ) {
 //browser reported as an iPhone/iPod touch -- do something here
 $this['isIos']= true;
 } else if($iPad) {
 //browser reported as an iPad -- do something here
 $this['isIos']= true;
 } else if($Android) {
 //browser reported as an Android device -- do something here
 $this['isIos']= false;
 } else if($webOS) {
 //browser reported as a webOS device -- do something here
 $this['isIos']= false;
 }
 //var_dump($this['isIos']);
}

then you can call the isIos variables in html section

{% if isIos %}
{% partial "some-partial-for-ios" %}
{% else %}
{% partial "some-partial-not-for-ios" %}
{% endif %}

reference: http://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.