1

I have a Picture content type that allows users to upload picture files, something that iOS does not support. Since Apple in 2012 can't support something my first computer running Netscape Navigator was able to do in the early 1990s, I'd like to give a message to iOS users that they will have to e-mail me the photos instead.

I installed the Browscap module but it only detects the user agent; it doesn't do anything by itself. On Drupal 6 I used Mobile Tools, but it has yet to see a stable release for D7.

I only want to show a single block on a single content type to iOS users, so I'm looking for the simplest possible solution.

2

2 Answers 2

2

My dull ax dealing with this same issue boils down to a little module helper function along the lines of:

function _MODULE_is_iOS() {
  if (strpos($_SERVER['HTTP_USER_AGENT'],'iPad')  !== FALSE || 
      strpos($_SERVER['HTTP_USER_AGENT'],'iPhone')!== FALSE || 
      strpos($_SERVER['HTTP_USER_AGENT'],'iPod')  !== FALSE) {
    return TRUE;
  } else {
    return FALSE;
  }
}

and then using that within my block hooks, eg,

if (_MODULE_is_iOS()) {
   $block['content']= // whatever I need for iOS
}

or from within the Block Admin PHP visibility area if in a pinch.

4
  • Will that method work with caching?
    – Clive
    Aug 17, 2012 at 13:56
  • That's quite the paradox of questions, @Clive as, as is true almost all the time with caching, is, it depends. But for something as simple as an informational block like this for what I am assuming is a logged in user, I'd just set it up with caching turned off. If it is something more customized, one could certainly cache the output with a $cid based upon the module, block delta and ua, eg, mymodule:block-xyzzy:ios or mymodule:block-xyzzy:desktop
    – Jimajamma
    Aug 17, 2012 at 14:27
  • 2
    Yeah for authenticated users this would be ok, but if anonymous users need to use the form then I think caching would obliterate this method. Especially if Varnish/similar is running. Your answer makes me happy though, dreaming back to a simpler time when you could get away with something like this without the 'best practice police' beating your door down ;)
    – Clive
    Aug 17, 2012 at 14:49
  • 2
    Re: forms, instead of using a block, similar logic could be put in a form_alter() to display the message in a help or other message inside the form itself, but then I know the BPP would already be in my kitchen :)
    – Jimajamma
    Aug 17, 2012 at 16:21
0

I've used mobile tools with D7 and it works really well.

Having said that, why not make a .tpl.php for your block that checks the user agent?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.