Match for device id example of using 51Degrees device detection. The example
shows how to:
Instantiate the 51Degrees provider from the specified data file with
the required properties, number of worksets in the pool and cache of the
- Specify name of the data file and properties the dataset should be
const char* fileName = argv;
const char* properties = "IsMobile";
fileName, &provider, properties, 4, 1000);
Retrieve a workset from the pool and use it for a single match.
fiftyoneDegreesWorkset *ws = NULL;
ws = fiftyoneDegreesProviderWorksetGet(&provider);
Get device ID from the match.
Extract the value of the IsMobile property
requiredPropertyIndex = fiftyoneDegreesGetRequiredPropertyIndex(ws->dataSet,
Use device ID instead of a User-Agent string to perform match:
valueName = fiftyoneDegreesGetString(ws->dataSet, ws->values->nameOffset);
isMobile = &(valueName->firstByte);
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 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:
For more information on the Pattern data model and how various entities
are related please see:
For more information on how device detection works please see: