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
Strongly Typed example of using 51Degrees device detection.
The example shows how to:
Specify name of the data file and properties the dataset should be
initialised with.
Instantiate the 51Degrees provider from the specified data file with
the required properties, number of worksets in the pool and cache of the
specific size.
Release the workset back into the pool of worksets to be reused in one
of the next matches.
fiftyoneDegreesWorksetRelease(ws);
Finally release the memory taken by the provider.
fiftyoneDegreesProviderFree(&provider);
This example assumes you have compiled with 51Degrees.c and city.c.
This will happen automatically if you are compiling as part of the
Visual Studio solution. Additionally, when running the program, the
location of a 51Degrees data file must be passed as a command line
argument if you wish to use Premium or Enterprise data files.
The size of the worksets pool parameter should be set to the maximum
(expected) number of concurrent detections to avoid delays related to
waiting for free worksets. Workset pool is thread safe. Initially the
number of created worksets in the pool is zero. When a workset is
retrieved from the pool a new workset is created if no worksets are
currently free and the number of worksets already created is less than
the maximum size of the workset pool.
This example differs from the Getting Started example by using boolean
values for the isMobile property instead of string values.
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.