本文介绍了testDeviceIdentifiers的AdMob kGADSimulatorID编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行集成了AdMob标语的应用程序时,我收到以下消息:

When running an app with an AdMob banner integrated I get the following message:

2020-12-02 00:54:21.835790+0000  <Google> To get test ads on this device, set: GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ kGADSimulatorID ];

但是,如果我将其转换为Swift 5,如下所示:

However if I convert this to Swift 5 as follows:

GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [ kGADSimulatorID ]

我收到一个编译错误:

Cannot convert value of type 'AnyObject' to expected element type 'Array<String>.ArrayLiteralElement' (aka 'String')

kGADSimulatorID 的定义是

GAD_EXTERN const id _Nonnull kGADSimulatorID;

所以我不确定如何将其转换为字符串吗?

so I'm not sure how to convert this to a string?

推荐答案

您需要先导入AdSupport ,然后获取移动设备设备广告标识符 uuid字符串.请注意,如果在模拟器上运行,下面的代码将返回 00000000-0000-0000-0000-000000000000 .您需要在真实设备上运行它:

You need to first import AdSupport and then get your mobile device advertising identifier uuid string. Note that the code below will return 00000000-0000-0000-0000-000000000000 if you run it on simulator. You need to run it on a real device:

ASIdentifierManager.shared().advertisingIdentifier.uuidString // "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

别忘了在Google admobs中设置测试设备ID

一旦您拥有adsIdentifier uuid字符串,只需将其添加到您的代码中即可:

Once you have the advertisingIdentifier uuid string just add it to your code:

GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [ "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ]

这篇关于testDeviceIdentifiers的AdMob kGADSimulatorID编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:23