Create Custom Notifications

Currently, there is no way for the GameScene to know when ads are getting loaded and presented to the player. You’ll take care of this problem by adding some custom notifications. With notifications,[63] you can broadcast specific information to designated observers. These observers then watch for the notifications, taking specific actions when they occur.

Open the AdMobHelper.swift file and add the following block of code to the bottom of the file:

 extension​ ​Notification​.​Name​ {
 static​ ​let​ userDidEarnReward = ​Notification​.​Name​(​"userDidEarnReward"​)
 static​ ​let​ adDidOrWillPresent = ​Notification​.​Name​(​"adDidOrWillPresent"​)
 static​ ​let​ adDidOrWillDismiss = ​Notification​.​Name​(​"adDidOrWillDismiss" ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.