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.
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:
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.
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.