iAD View Freezes On Ad Close

半城伤御伤魂 提交于 2019-12-24 11:35:53

问题


Ok, so after testing on the simulators it turns out that this issue is only occurring on actual devices... How would I fix this?


I am making an iOS app with SpriteKit and am implementing iAD. Everything works more or less like I expect it too, except for one thing. When I tap on the ad, it brings me to a full screen ad, as expected, but when I close that ad the current view freezes, as in nothing happens visually. I know the app is still running because when I click the banner ad again and close out of it again the game returns to normal and the game had progressed while visually frozen. This is how the banner is initialized in my view controller class (the iAD delegate):
self.canDisplayBannerAds = YES;

CGRect bannerFrame = CGRectMake(0, 20, scene.size.width, 50);

banner = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
banner.delegate = self;
banner.frame = bannerFrame;
[banner setAlpha:0];
[self.view addSubview:banner];

And these are the loading methods, also in the view controller class:

- (void) bannerViewDidLoadAd:(ADBannerView *) bannerM
{
    NSLog(@"Ad Loaded");
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [bannerM setAlpha:1];
    [UIView commitAnimations];
}

- (void) bannerView:(ADBannerView *)bannerM didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"Ad Failed");
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [bannerM setAlpha:0];
    [UIView commitAnimations];
}

I don't really understand the problem or why it is happening... Any help would be appreciated!

Thanks,
StrongJoshua

EDIT Here are the two methods that are called when the banner ads open and close:

- (BOOL) bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    if(playing)
    {
        NSLog(@"Ad Pause");
        SKView *v = (SKView *)self.view;
        NSLog(@"2");
        SKScene *s = (SKScene *)v.scene;
        NSLog(@"3");
        WBPlayScene *p = (WBPlayScene *) s;
        NSLog(@"4");
        [p.logic pause:YES];
        NSLog(@"Done");
    }
    return YES;
}

- (void) bannerViewActionDidFinish:(ADBannerView *)banner
{
    if(playing)
    {
        NSLog(@"Ad Unpause");
        [((WBPlayScene *)((SKView *)self.view).scene).logic pause:NO];
    }
}

FIXED The reason for all those NSLogs is because the game crashes when I try to pause it. The game crashes after "2" is reached, so at SKScene *s = (SKScene *)v.scene;. It gives the error [UIView scene]: unrecognized selector sent to instance and I don't understand why... Solution: To fix this side issue I changed self.view to self.originalContentView and it got the SKView instead of the ad banner's view.

Thanks very much for your help!


回答1:


SOLVED: I had to remove the call to enable ad display self.canDisplayBannerAds because it interfered with my self-created banner.



来源:https://stackoverflow.com/questions/22595148/iad-view-freezes-on-ad-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!