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.
#import <AdSupport/ASIdentifierManager.h>
#include <CommonCrypto/CommonDigest.h>
- (NSString *) admobDeviceID
{
NSUUID* adid = [[ASIdentifierManager sharedManager] advertisingIdentifier];
const char *cStr = [adid.UUIDString UTF8String];
unsigned char digest[16];
CC_MD5( cStr, strlen(cStr), digest );
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
return output;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With