This tutorial illustrates how to return a match for a Device Id. It shows how to first get the Device Id from a match, then get a match for that Device Id and return the value of the IsMobile property. This can be useful to look at devices that have already been matched at a previous date.
Code and Explanation
Match for device id 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 main focus of this example is on extracting the device ID and later
reusing it to obtain device information. Device ID is a more efficient
way of storing information about devices as the entire ID can be stored
as an array of bytes, where as when storing specific properties you would
be dealing with strings, integers and doubles for each property.
The 51Degrees device ID is composed of four numbers separated by hyphens.
Each number corresponds to the ID of the relevant profile. Each profile is
a collection of property - value pairs for one of the components.
A complete ID has one profile for each of the four components:
Hardware-Software-Browser-Crawler.
For more information on the Pattern data model and how various entities
are related please see:
https://51degrees.com/support/documentation/device-detection-data-model
For more information on how device detection works please see:
https://51degrees.com/support/documentation/how-device-detection-works
Summary
In this tutorial you have seen how to use the detector to retrieve the
IsMobile
property for a pre-defined Device ID 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 files they exist in please see the
Property Dictionary
.