This tutorial illustrates the basic use of the 51Degrees API using the Hash Trie algorithm. This Hash Trie 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 with Hash Trie.
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.
Summary
In this tutorial you have seen how to use the detector to retrieve the
IsMobile
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
IsCrawler
,
PriceBand
,
HardwareVendor
and
ScreenInchesWidth
. For a full list of properties and the data file versions they exist in please see the
Property Dictionary
.