如何获得“哈希设备ID”在ios上测试admob [英] How to get a "hashed device id" for testing admob on ios

查看:353
本文介绍了如何获得“哈希设备ID”在ios上测试admob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实施AdMob时,您可以定义一系列测试ID,以便Google知道向这些设备投放测试广告,而不是真实广告。但是,它需要散列设备ID。这对我来说似乎有点模糊。他们在谈论什么ID以及他们希望我使用什么样的哈希方法?

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" ];


推荐答案

我想出了如何生成AdMob设备ID:
只需计算advertisingIdentifier的MD5。

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;

}

这篇关于如何获得“哈希设备ID”在ios上测试admob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆