Page 1 of 1

Show correct app link to mobile users

Posted: Thu Sep 12, 2013 6:02 am
by addisonlee
Hi - I have a mobile app for iphone, blackberry and android. I'd like to use WURLF to detect the users OS and then print the correct URL to the app for the users operating operating system. Something like

Code: Select all

<a href="<?php echo $applink ?>">Download the <?php echo $appname ?></a>
. I can't seem to find any documentation regarding this. Can anyone help at all? I'm using Wordpress by the way. Thanks!

Re: Show correct app link to mobile users

Posted: Thu Sep 12, 2013 11:37 am
by kamermans
You can certainly do this with WURFL. We can't really write up a full example, but this is essentially the what you would do in your page:

Code: Select all

<?php
// Create a WURFL Cloud Config
$config = new WurflCloud_Client_Config();

// Set your API Key here
$config->api_key = 'xxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// Create a WURFL Cloud Client
$client = new WurflCloud_Client_Client($config, new WurflCloud_Cache_Null());

// Detect the visitor's device
$client->detectDevice();

$os = $client->getDeviceCapability('device_os');

if ($os == 'Android') {
	// Show Android app link
} else if ($os == 'iOS') {
	// Show iOS app link
}

Re: Show correct app link to mobile users

Posted: Fri Sep 13, 2013 7:14 am
by addisonlee
Great! Thanks for your helpful reply. If for example I wnated to include more than one OS (ie 'Windows Mobile OS' and 'Windows Phone OS') in one if statement. How do I do that?

Also, If I wanted to include a link to all unsupported devices, Do I end it with

Code: Select all

else {}
of do I use the

Code: Select all

else if ($os == 'Other Smartphone OS')
?

Re: Show correct app link to mobile users

Posted: Fri Sep 13, 2013 8:20 am
by sm_support2
The following link contains the list of all WURFL Cloud capabilities:

http://www.scientiamobile.com/wurflCapability

if you look for 'device_os' (we have a nice 'ajaxy' search field at the top), you'll find a list of all accepted values.

Thank you

Re: Show correct app link to mobile users

Posted: Fri Sep 13, 2013 11:18 am
by kamermans
You can include more "else if" statements:

Code: Select all

if ($os == 'Android') {
   // Show Android app link
} else if ($os == 'iOS') {
   // Show iOS app link
} else if ($os == "RIM OS") {
   // Show BlackBerry app link
} else if ($os == "Windows Mobile OS" || $os == "Windows Phone OS") {
   // Show Windows app link
} else {
   // No app available
}