This tutorial illustrates the basic use of the 51Degrees API using the Pattern algorithm. This Pattern getting started tutorial will show you how to create a provider, how to create a dataset and how to obtain a value for the IsMobile property.
Code and Explanation
Getting started example of using 51Degrees device detection using Pattern.
The example shows how to:
Specify name of the data file and properties the dataset should be
Release the workset back into the pool of worksets to be reused in one
of the next matches.
Finally release the memory taken by the 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.
In this tutorial you have seen how to use the detector to retrieve the
property for a pre-defined User-Agent string. The example can easily be modified to retrieve the value of any other property. Premium and Enterprise data files provide considerably more properties such as
. For a full list of properties and the data file versions they exist in please see the