Search code examples
ioscocos2d-iphoneiadinterstitial

App freeze after iAd/google interstitial popup


I am experiencing a very weird issue with interstitials in cocos2d(version 3.1.0) This is the code I use to load both interstitials.

- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
    [interstitial presentFromRootViewController:[CCDirector sharedDirector]];
    interstitial.delegate = nil;
    interstitial = nil;
}
- (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd {
    [interstitialAd presentFromViewController:[CCDirector sharedDirector]];

}

Everything seems fine and works fine until you put and hold your finger on the display before the interstitial has popped, then when you cancel the touch(release the finger) and close the popup window the app becomes unresponsive, the touch handler does not work at all and you have to restart the app. I am struggling for several hours with no success of finding the issue causer. Could it be something with the CCDirector stop and start animation methods?


Solution

  • I found a workaround to the bug. What I did is to disable the respond manager before the google/iAD interstitial is shown, you can see the methods below.

    - (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
        [[[CCDirector sharedDirector]responderManager]setEnabled:false];
        [interstitial presentFromRootViewController:[CCDirector sharedDirector]];
        interstitial.delegate = nil;
        interstitial = nil;
    }
    - (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd {
        [[[CCDirector sharedDirector]responderManager]setEnabled:false];
        [interstitialAd presentFromViewController:[CCDirector sharedDirector]];
    }
    

    After that I enabled it again in the - (void) startAnimation in CCDirectorIOS.m file by putting the following code.

    if (![[self responderManager]isEnabled]) {
            [[self responderManager]setEnabled:true];
    }
    

    I know that this is not an elegant solution, because changing the library code directly is not always a good idea, but I could not find any other alternative. I think that this is a cocos2d bug, but I am not sure, may be someone more experienced can point out the exact issue. I have no idea if this bug is present in the newest cocos2d version.

    EDIT: This behaviour is also present in the newest version.