Reputation: 13713
I am trying to display an admob interstitial ad after receiving a successful ad call :
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
DLog(@"interstitialDidReceiveAd");
[ad presentFromRootViewController:self];
}
self
is the ViewController
instance (which is the root view controller as implemented by the SpriteKit template) and for some reason it displays the ad (which is good) but restarts the entire scene.
I should note that the ad request is done way after the scene is created and being run.
I also noticed this behavior when I tried adding a view to this controller's view property (which is a SpriteKit SKView
instance)
And ideas ?
Upvotes: 0
Views: 639
Reputation: 3439
There's something funky going on here that's more than just displaying an interstitial. I have a sprite kit project setup where I display the UIImagePickerController from the rootViewController via:
#pragma mark - ImageCatureDelegate methods
-(void)requestImagePicker
{
UIImagePickerController *imagePicker = [UIImagePickerController new];
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
}
#pragma mark - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[picker dismissViewControllerAnimated:YES completion:^{
SKTexture *imageTexture = [SKTexture textureWithImage:image];
CIFilter *sepia = [CIFilter filterWithName:@"CISepiaTone"];
[sepia setValue:@(0.8) forKey:kCIInputIntensityKey];
imageTexture = [imageTexture textureByApplyingCIFilter:sepia];
SKView *view = (SKView *)self.view;
MyScene *currentScene = (MyScene *)view.scene;
[currentScene setPhotoTexture:imageTexture];
}];
}
during the callback, nothing special is done except dismissing the modal. If admob is pushing a new VC you may see this issue, but if it's displaying a literal modal VC modally... then you shouldn't see this issue. You may want to look into exactly what happens when you push an interstitial ad. If this is the case, and this is the only method you can use, You'll have to NSCode or something to keep the game's state so it can be loaded back up when the interstitial disappears.
Edit:
To append to your solution above, if you use viewWillLayoutSubviews to correct the portrait/landscape issue in SpriteKit, be sure to do it as such so this only happens 'once'
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
MyScene * scene = [[MyScene alloc] initWithSize:skView.bounds.size andLevelNumber:1];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
Upvotes: 0
Reputation: 13713
As I thought... I was doing something wrong...
If you stumble upon this problem :
I create my scene in the view controller's method viewWillLayoutSubviews
(until this method the view bounds are NOT updated with the desired orientation)
When the interstitial ad is presented this method is called again and of course the scene is recreated as well. So just add a boolean member indicating if the scene was already loaded for creating the scene only once.
Poof, problem is gone:)
Upvotes: 1