OGeek|极客世界-中国程序员成长平台

标题: ios - 为 testDevices 和测试广告查找 Google DFP SDK 设备 ID [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:31
标题: ios - 为 testDevices 和测试广告查找 Google DFP SDK 设备 ID

我正在尝试使用 Google 的测试广告单元使用 Google 的 DFP SDK 调试和开发我的应用。这样做需要将设备的标识符(如 Google 定义的那样)添加到 DFPRequest 对象的 request.testDevices[] 属性中。

最新版本的 DFP SDK 添加了一条日志消息以显示当前设备的 ID,还添加了对 kGADSimulatorID 的支持,以便在 sim 中运行。这允许开发人员运行应用程序,从控制台复制设备 ID,然后修改代码以将其添加到 testDevices[] 数组。但是,不存在用于在运行时检测 ID 并持续注册当前设备以接收测试广告的文档或工具。

如何获得相当于 Google 的 -[GADDevice deviceIdentifier] 调用(这不是公共(public)方法),这是我可以添加到 testDevices[ 的 ID ] 数组并让我的应用始终在任何设备上调用测试广告?



Best Answer-推荐答案


Google 的 SDK 使用规定的 [ASIdentifierManager sharedManager].advertisingIdentifier 属性作为其标识符的基础。然后它根据广告标识符创建一个 MD5 散列。因此,如果设置了 isUsingTestAds 标志,则以下代码允许我的应用在其运行的任何设备上调用测试广告:

DFPRequest *request = [DFPRequest request];
...
if (isUsingTestAds) {
    NSString *currentDeviceID = [self md5WithString:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString]];
    request.testDevices = @[ kGADSimulatorID,                       // iOS simulator
                             currentDeviceID
                            ];
...

md5WithString 函数是通用的,几乎可以在任何地方使用。

关于ios - 为 testDevices 和测试广告查找 Google DFP SDK 设备 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30945335/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4