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:
dataFile = settings.V3_WRAPPER_DATABASE
properties = settings.PROPERTIES
cacheSize = settings.CACHE_SIZE
poolSize = settings.POOL_SIZE
provider = fiftyone_degrees_mobile_detector_v3_wrapper.Provider(dataFile, properties, cacheSize, poolSize)
match = provider.getMatch(userAgent)
def isMobile(userAgent): match = provider.getMatch(userAgent) if (match.getValue('IsMobile') == 'True'): return TrueThis example can be run in any directory, but assumes your settings file contains a valid dataFile location and has the IsMobile property selected.
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.