One-liner to identify mobile apple (iOS) browsers

So, it struck us today, that Apple's mobile browsers does not support file uploads from web sites (
).

The reason for this, is that the user does not have access to the file system in iOS (no "My documents"), and inter-app communication is severely lacking. Anyway, if you are to design a web site to accommodate iOS users, you might want to hide your file upload control and/or show a friendly message to users using these devices. A one-liner that identifies such a browser is:

Regex.IsMatch(Request != null && Request.UserAgent != null ? Request.UserAgent : "", "Mozilla\\/5.0 \\(iPod|iPad|iPhone.+?\\).*?Mobile");

The code snippets expects:
  • That you have references to System.Text.RegularExpressions.
  • That you are running in a web environment (Request)
The boolean result indicates whether or not your user is visiting your site from an Apple mobile device.

Thanks, Sitepoint, for the User agent reference.

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints