When implementing AdMob you can define an array of test IDs so that Google knows to serve test ads to these devices, instead of real ads. However, it requires "hashed device IDs". This seems a little vague to me. What ID are they talking about and what hashing method do they expect me to use?
I'm talking about the bit that should go in here:
request.testDevices = @[ @"hashed-device-id" ];
I figured out how to generate the AdMob device ID: Just compute the MD5 of the advertisingIdentifier.
In Swift 2, Xcode 7.3 I did this and the ad banner now shows test ad when I run in simulator:
Start the app without setting the test devices and have a look at the debugger output. There you'll find a message like:
I guess the message is self explaining.
Check out ASIdentifierManager. It is created specifically for accessing unique device identifiers to be used for serving ads. You can get a unique identifier for the current device like so:
The alternative way to access the unique identifier for a device is:
However, as per Apple's documentation,
identifierForVendor
is not intended to be used for advertising purposes.find some log like following
or
I get the device id in such way: Swift 3.0
Don't forget to add
#import <CommonCrypto/CommonCrypto.h>
to the ObjC-Swift bridging header that Xcode creates.The extension for String class was taken here.