What's Covered
51Degrees device detector returns all detection results as a string. This tutorial demonstrates how to return results for the IsMobile property value as a boolean.
Code and Explanation
Getting started example of using 51Degrees device detection. The example
shows how to:
my $filename = "../../data/51Degrees-LiteV3.2.dat";
my $propertyList = "IsMobile"
my $cacheSize = 10000;
my $poolSize = 20;
my $provider = new FiftyOneDegrees::PatternV3::Provider( $dataFile, $properties, $cacheSize, $poolSize);
my $match = $provider->getMatch($userAgent)
sub isMobile { my $match = @_[0]; my $isMobileString = $match->getValue("IsMobile"); if ($isMobileString eq "True") { return 1; } else { return; } }This example assumes you are running from the original subdirectory i.e. Device-Detection/perl/examples/ and the 51Degrees Perl module is installed.
Summary
In this tutorial you have seen how to use the detector to retrieve the IsMobile property for a pre-defined User-Agent string. It sets a boolean value to true or false from the original string value of "True" or "False", making if statements simpler to test.