Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a "hashed device id" for testing admob on ios

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" ];
like image 300
Jasper Kennis Avatar asked Jul 15 '14 13:07

Jasper Kennis


1 Answers

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;

}
like image 52
Felix Avatar answered Oct 07 '22 11:10

Felix