iAd in Sprite Kit Pauses the scene

谁都会走 提交于 2020-01-14 05:21:50

问题


I have a problem implementing iAd banner, everything works fine until the banner is tapped, the banner navigation works fine.

When i close the add the Sprite kit Scene is like frozen, update method is working because i can see the NSLog's there....but everything is just as it was before tapping the add, even if i tap , nothing works or at least its not being showed...

So my question is How to "resume" the game after closing the add, iAd uses some kind of self.view.paused = YES; ?

I've been reading a lot, even at apple documentation but i can't find the way they "pause" my game, here i show you the implementation of iAD which is so poor i guess..

@implementation GoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];


    skView = (SKView *)self.view;
    //skView.showsFPS = YES;
    //skView.showsNodeCount = YES;

    // Create and configure the scene.
    scene = [GoMyScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    // Present the scene.
    NSLog(@"%@",skView);
    self.canDisplayBannerAds = YES;



    [skView presentScene:scene];
}

- (BOOL)shouldAutorotate
{
    return YES;
}
-(void)viewWillLayoutSubviews{

}
- (NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}
- (BOOL)prefersStatusBarHidden {
    return YES;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    NSLog(@"ADD ON");

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

}



-(void)bannerViewActionDidFinish:(ADBannerView *)banner{

    NSLog(@"banner finished");
    //[self bannerViewActionShouldBegin:banner willLeaveApplication:YES];
    //[UIView setAnimationBeginsFromCurrentState:YES];


}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner{
    NSLog(@"banner starting to show");

}

回答1:


There is usually a problem when using self.canDisplayBannerAds with spritekit. I have tried endlessly to get it to work, but to no avail. Instead, I use this code:

adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.delegate = self;
[adView setFrame:CGRectMake(0, 0, 1024, 768)]; // set to your screen dimensions
[adView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:adView];

First initialize a ADBannerView *adView variable in your Viewcontroller's interface file, then you can use the above code in your ViewDidLoad method.

It works perfectly for me, and doesn't have any issues with pausing or unresponsive screen after clicking the ad.




回答2:


And if anyone has any trouble with making this in swift here is the same code (just changed some bits)in swift. This worked just fine for me!

            AdBanner = ADBannerView()
        AdBanner.frame = CGRectZero
        AdBanner.delegate = self
        self.AdBanner.frame = CGRectMake(0, self.view.frame.size.height-self.AdBanner.frame.size.height, self.AdBanner.frame.size.width, self.AdBanner.frame.size.height)
        AdBanner.backgroundColor = UIColor.clearColor()
        self.view .addSubview(AdBanner)



回答3:


For anyone that run across this question using iADBannerView. Here is the full code for a working iADBannerView. Im using this in Xcode-7 Beta with Objective-C. Pausing and resuming the game works automatically with no additional code for pausing or resuming.

#import <iAd/iAd.h>

@interface GameScene()<ADBannerViewDelegate>{
ADBannerView *adBanner;
}
- (void)didMoveToView:(SKView *)view {
[self setUpInitalBanner];
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
NSLog(@"Got iAD");
CGRect visibleFrame = adBanner.frame = CGRectMake(0,0 +self.view.frame.size.height -adBanner.frame.size.height, self.view.frame.size.width,50);
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
adBanner.layer.zPosition = 100;
[self.view addSubview:adBanner];
[adBanner setHidden:false];
[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{[banner setFrame:visibleFrame];}completion:nil];
[adBanner setAlpha:1];
[UIView commitAnimations];
}
-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{
NSLog(@"Leaving app for iAD");
adBanner.frame = CGRectMake(0, 0 +self.view.frame.size.height -banner.frame.size.height, self.view.frame.size.width, 50);
return YES;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
NSLog(@"Banner Did Finish Action");
adBanner.frame = CGRectMake(0, 0+self.view.frame.size.height-banner.frame.size.height, self.view.frame.size.width, 50);
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(@"Failed To Get iAD");
[adBanner setHidden:true];
CGRect hiddenFrame = adBanner.frame = CGRectMake(0, 0 +self.view.frame.size.height +adBanner.frame.size.height, self.view.frame.size.width, 50);
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:adBanner];
adBanner.layer.zPosition = 100;
[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{[adBanner setFrame:hiddenFrame];} completion:nil];
[adBanner setAlpha:0];
[UIView commitAnimations];
}

-(void)setUpInitalBanner{
adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 50)];
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
adBanner.delegate = self;
adBanner.layer.zPosition = 100;
}


来源:https://stackoverflow.com/questions/24169442/iad-in-sprite-kit-pauses-the-scene

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