THIS MAY BE HELPFUL FOR SOMEONE!!!
I got the same error when I used the Ad Unit Ids defined in the AdMob app for testing on my iPhone. Of course the device has to be registered as a Test Device. I was adding the Test Device Id programmatically.
This is where I went a wrong route. The documents has clearly mentioned steps on how to register a device as a Test Device. Instead all that I somehow made my mind to register the device's UDID as the Test Device Id(This is the mistake I made. Now I accept that it is purely my ignorance). After searching through most of the solutions provided in SO, and some of the other blogs, I just wanted to try the AdMob UI to add a test device. There I saw Advertising ID/IDFA which had a link on how to find the advertising ID/IDFA.
AdMob -> Settings -> Test Devices -> Add Test Device
Just to reiterate the steps which fixed the issue for me:
Take/copy the Ad Unit Ids which you defined in your AdMob app
Put those Ad Unit Ids in your code.(I used xcconfig files to separate Dev vs Prod)
Run the app by now you might have setup all your ad plugging code
Check the Xcode console(important), there you will see the Test Device Id suggested by Google. Which will look something like below:
<Google> To get test ads on this device, set:
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @"2077ef9a63d2b398840261c8221a0c9b" ]; // Pay attention at this bolded id, this is the one which we want.
The above code is in Obj-C. Use the below code in Swift 5+
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = ["2077ef9a63d2b398840261c8221a0c9b"]
Take away: Test Device Identifier is not UDID of the device but the Advertising Identifier. Check this: https://support.google.com/admob/answer/9691433?hl=en#ID
Tip: I used the Dev.xcconfig file to add the Test Device identifiers, so that the Prod.xcconfig is clean without those test device ids and the app can be submitted without any code changes.
/// Extract those test device ids from the xcconfig file.
if let testIDs = self.extractTestDeviceIDs() {
debugPrint("FOUND: test IDs: ", testIDs)
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = testIDs
} else {
debugPrint("NOT FOUND: test IDs")
/// NoOp: This has to be prod environment
/// If the test IDs are not configured, then also Ads should be initialized.
}
GADMobileAds.sharedInstance().start { initStatus in
debugPrint("GAD Ads... Init Status: ", initStatus)
}