Reputation: 850
I use the code below:
let request : GADRequest = GADRequest ()
request.testDevices = ["xxxxxxx",kGADSimulatorID]
But I am getting the below warning:
'testDevices' is deprecated: Use GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers.
Do I use a syntax to remove the warning?
Upvotes: 11
Views: 12985
Reputation: 11646
googleAds sdk site answers differently, You have to copy the id that has been logged:
(https://developers.google.com/admob/ios/test-ads)
...Load your ads-integrated app and make an ad request. Check the console for a message that looks like this:
To get test ads on this device, set:
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers =
@[ @"2077ef9a63d2b398840261c8221a0c9b" ];
Upvotes: 1
Reputation: 75
Swift Solution
Works with disabled app tracking. Without any external dependencies.
import CryptoKit
var deviceId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
if deviceId == UUID(0).uuidString {
deviceId = UIDevice.current.identifierForVendor?.uuidString ?? ""
}
let md5 = Insecure.MD5.hash(data: Data(deviceId.utf8))
.map { String(format: "%02hhx", $0) }.joined()
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [ md5 ]
Upvotes: 0
Reputation: 4481
This is a modification to 10623169's answer.
To get a valid ID, for the current device, that can be set in "testDevices", get the MD5 of this: UIDevice.current.identifierForVendor?.uuidString
The asIdentifier
value can be completely invalid if the user hasn't given permission for tracking. But the UIDevice.current.identifierForVendor
is a valid UUID for the app, that will persist across launches (but perhaps not if you delete the app and reinstall).
Upvotes: 2
Reputation: 1044
It turns out the AdMob
/GoogleAdManager
deviceId
can be found by computing the MD5 of the advertisingIdentifier. This way you can retrieve and use the test deviceId
in code without having to previously have got a device's identifier from the console log.
To avoid the faff of using an ObjC-Swift bridging header (getting MD5 via <CommonCrypto/CommonCrypto.h>
), I'd suggest using a Swift wrapper around the CommonCrypto
framework, e.g this one:
Using the above framework (which adds an extension property to String
for computing the MD5 hash), it is a simple matter of querying against:
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers ?? []).contains(ASIdentifierManager.shared().advertisingIdentifier.uuidString.md5)
Upvotes: 3
Reputation: 837
You should use this:
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = ["YOUR IDENTIFIER PRINTED ON DEBUGGER"]
Instead of:
request.testDevices = ["YOUR IDENTIFIER PRINTED ON DEBUGGER"]
Upvotes: 16
Reputation: 2908
You don't have to set this at all. As the AdMob Developer Doc says:
iOS simulators are automatically configured as test devices.
Source: https://developers.google.com/admob/ios/test-ads#enable_test_devices
Upvotes: 2
Reputation: 233
Use the syntax to remove the warning:
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers
Upvotes: 1