0
votes

I created a method in ViewController.h called - (void)showFullScreenAd.

I tried to call it inside my scene. I tried [self.view.window.rootController showFullScreenAd]. Can't find this method.

I tried ViewController *vc = [[ViewController alloc] init]

It did successfully NSLog "Interstitial Ad request". But no ad shown.

If I use the method directly in ViewController.m - viewDidLoad, it NSLog the same message "Interstitial Ad request" and display an interstitial Ad.

2
Why not use a NSNotification ? Google that. Also, you are not giving enough context or clarity for anybody to help you efficiently, so you might end up not getting much help. It's also possible that you are not understanding some fundamental concepts as it appears you might be creating a new ViewController instance in your scene, which is in no way going to help you communicate with the ViewController presenting your scene.prototypical
@prototypical Yep, I google it, and found it really helpful. Thanksuser3882307

2 Answers

0
votes

A suggestion to how to use iAd;

in ViewController.m:

MyScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.viewController = self;

and then in your MyScene.h put those lines:

#import "ViewController.h"

@property (nonatomic) ViewController *viewController;

also don't forget to add iAd in ViewController.m;

[self.view addSubview:adView];
0
votes

I would use notifications: the SKScene object posts a system-wide notification (NSNotification) to the notification center (NSNotificationCenter), and the targeted view controller just 'registers' (i.e., listens) to that same notification and implements a handler method. This is a pervasive pattern in Objective-C/Cococa.

Some benefits are:

  1. It is extensible: if in the future, you want to send the same message to the view controller form a different scene, just post the same notification from the new scene: no need to include headers and define a new property. Only need yo include the definition of the notification name.

  2. The view controller owns the view, and the view presents the scene. By not referencing the view controller from the scene, you avoid the risk of a reference cycle and hence a memory leak.

By the way, this is what I do in my games.