Finding Google DFP SDK device ID for testDevices and test ads

730 views Asked by At

I'm trying to debug and develop my app with Google's DFP SDK using Google's test ad units. Doing this requires that a device's identifier (as Google defines it) be added to the request.testDevices[] property of a DFPRequest object.

Recent versions of the DFP SDK added a log message to display the current device's ID, and also added support for the kGADSimulatorID for running in the sim. This allows the developer to run the app, copy the device ID from the console, then modify the code to add it to the testDevices[] array. However, no documentation or facility exists for detecting the ID at run-time and consistently register the current device to receive test ads.

How can I get the equivalent of Google's -[GADDevice deviceIdentifier] call (this isn't a public method), which is the ID that I can then add to the testDevices[] array and make my app always call test ads on any device?

1

There are 1 answers

1
chad On

Google's SDK uses the prescribed [ASIdentifierManager sharedManager].advertisingIdentifier property as the basis for its identifier. It then creates an MD5 hash from the advertising identifier. So the following code allows my app to call test ads on any device its running on, if the isUsingTestAds flag is set:

DFPRequest *request = [DFPRequest request];
...
if (isUsingTestAds) {
    NSString *currentDeviceID = [self md5WithString:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString]];
    request.testDevices = @[ kGADSimulatorID,                       // iOS simulator
                             currentDeviceID
                            ];
...

The md5WithString function is generic, available from almost anywhere.