[iOS] Mopub SDK (5.5.0) taking too long to initialize before first screen loads

mopub

#1

I implemented a native ad on my first screen and it was loading ok until recently. The SDK was configured in my AppDelegate as it should be so nothing changed.

 let sdkConfig = MPMoPubConfiguration(adUnitIdForAppInitialization: "XXXXX")
         sdkConfig.loggingLevel = MPLogLevel.debug
         MoPub.sharedInstance().initializeSdk(with: sdkConfig, completion: nil)

Out of nowhere as I was working on other things the ad stops loading and I get this on the console:

**[MoPub][MPConsentManager] Attempting to synchronize consent state**

**[MoPub][MPConsentManager] Ad unit used for GDPR sync: XXXXXXXX**

**[MoPub][MPHTTPNetworkSession] (21) bad request**

**[MoPub][MPNativeAdRequest][XXXXX] Attempting to load ad**

**[MoPub][MPAdServerCommunicator] (23) Ad prevented from loading. Error: Ad requested before initializing MoPub SDK. The MoPub SDK requires initializeSdkWithConfiguration:completion: to be called on MoPub.sharedInstance before attempting to load ads. Please update your integration.**

**[MoPub][MPNativeAdRequest] Error: Couldn't retrieve an ad from MoPub. Message: Error Domain=com.mopub.iossdk Code=23 "Ad prevented from loading. Error: Ad requested before initializing MoPub SDK. The MoPub SDK requires initializeSdkWithConfiguration:completion: to be called on MoPub.sharedInstance before attempting to load ads. Please update your integration." UserInfo={NSLocalizedDescription=Ad prevented from loading. Error: Ad requested before initializing MoPub SDK. The MoPub SDK requires initializeSdkWithConfiguration:completion: to be called on MoPub.sharedInstance before attempting to load ads. Pl [MoPub][MPNativeAdRequest][XXXX] Ad failed to load: (-1000) Connection error**

**Optional(Error Domain=com.mopub.nativeads Code=-1000 "Connection error" UserInfo={NSLocalizedDescription=Connection error})**

**[MoPub][MPConsentManager] Consent synchronization failed: (21) bad request**

**[MoPub][MoPub] SDK initialized and ready to display ads.**

It seems to initialize the SDK after the first screen loads which results in the ad not having the chance to load. To confirm this is the case I delayed loading the ad for 0.1 seconds.

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
                self.loadNativeAd()
            }

This worked but it feels like a temporary fix to a larger issue. What am I doing wrong? This issue popped up after updating to 5.5.0


#2

Hi,
If this issue still affecting you, can you please reach out to support@mopub.com providing the following info?

  • Account:
  • App Name:
  • OS:
  • Ad unit ID / Line Item ID:
  • MoPub SDK ver:
  • Code snippet:
  • Have you followed our integration instructions: YES / NO
  • Have you customized your integration? YES/ NO
  • Have you reviewed the code of our Sample App? YES/ NO

Many thanks!