在实现 AdMob 时,您可以定义一组测试 ID,以便 Google 知道向这些设备转换测试广告,而不是真正的广告。但是,它需要“哈希设备 ID”。这对我来说似乎有点模糊。他们在谈论什么 ID,他们希望我使用什么哈希方法?
我说的是应该放在这里的部分:
request.testDevices = @[ @"hashed-device-id" ];
最佳答案
我想出了如何生成 AdMob 设备 ID: 只需计算广告标识符的 MD5。
#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;
}
关于ios - 如何获取 "hashed device id"以在 ios 上测试 admob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24760150/