Hide Admob banner in iOS with SpriteKit - ios

I'm using a 2d game engine called Sprite kit within Xcode and i want to hide my ad banner in specific areas such as the game scene and then show it once it's game over for the player. But i'm having trouble trying to access the hidden property of the banner within other scenes/classes.
GameViewController.h
#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>
#import <GoogleMobileAds/GoogleMobileAds.h>
#import <AVFoundation/AVFoundation.h>
#interface GameViewController : UIViewController
-(void) hideBanner;
#end
GameViewController.m
#implementation GameViewController
-(void) hideBanner {
self.bannerView.hidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Create a banner ad and add it to the view hierarchy.
self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
//TEST UNIT ID
self.bannerView.adUnitID = #"ca-app-pub-3940256099942544/2934735716";
self.bannerView.rootViewController = self;
[self.view addSubview:self.bannerView];
GADRequest *request = [GADRequest request];
request.testDevices = #[ #"*log id*" ];
[self.bannerView loadRequest:request];
}
GameScene.h
#class GameViewController;
#interface GameScene : SKScene <SKPhysicsContactDelegate>
#property (strong, nonatomic) GameViewController *gameViewController;
#end
GameScene.m
//This line of code will be executed in the "performGameOver" method but it does not work and the banner is still shown?
[self.gameViewController hideBanner];

You should use NSNotification
In viewController.m
- (void)handleNotification:(NSNotification *)notification {
if ([notification.name isEqualToString:#"hideAd"]) {
[self hidesBanner];
}else if ([notification.name isEqualToString:#"showAd"]) {
[self showBanner];
}}
-(void)hidesBanner {
NSLog(#"HIDING BANNER");
[adView setAlpha:0];
self.bannerIsVisible = NO;
}
-(void)showsBanner {
NSLog(#"SHOWING BANNER");
[adView setAlpha:1];
self.bannerIsVisible = YES;
}
In your scene:
Sends message to viewcontroller to show ad.
[[NSNotificationCenter defaultCenter] postNotificationName:#"showAd" object:nil];
Sends message to viewcontroller to hide ad.
[[NSNotificationCenter defaultCenter] postNotificationName:#"hideAd" object:nil];
More info:
https://stackoverflow.com/a/21967530/4078517

Related

MPMediaPicker does not show

In a sample app that I'm making for Apple, I cannot get the MPMediaPickerController to show.
I've already added the NSAppleMusicUsageDescription key in the info.plist file, and this is what makes my post different from any other answers found online.
I've also tried adding CoreMedia.framework.
I'm using XCode 10 beta 4
The app never asks for permissions to access the media library, and when I present the picker, the mediaPickerDidCancel method is called right away.
What am I doing wrong?
Thanks for any help!
Header file:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MPMediaPickerController.h>
#interface ViewController : UIViewController<MPMediaPickerControllerDelegate>
#end
Objc file:
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController ()
#end
#implementation ViewController {
MPMediaPickerController *picker;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)selectButtonPressed:(id)sender {
picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
[picker setDelegate: self];
[picker setAllowsPickingMultipleItems: NO];
picker.prompt = #"Select a Song.";
UIViewController *rootController = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootController presentViewController:picker animated:YES completion:^{
NSLog(#"Complete!");
}];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) collection {
MPMediaItem *firstItem;
for (MPMediaItem *item in collection.items) {
firstItem = item;
break;
}
MPMusicPlayerController *samplePlayer = [MPMusicPlayerController applicationMusicPlayer];
[samplePlayer setShuffleMode: MPMusicShuffleModeOff];
[samplePlayer setRepeatMode: MPMusicRepeatModeOne];
[samplePlayer beginGeneratingPlaybackNotifications];
// self.mediaItem chosen using MPMediaPickerController
[samplePlayer setQueueWithItemCollection:[[MPMediaItemCollection alloc] initWithItems:#[firstItem]]];
[samplePlayer prepareToPlay];
// Assume that song is at least 120 seconds long
[samplePlayer play];
}
#pragma mark - delegate methods and segues
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {
[self dismissViewControllerAnimated:true completion:^{
}];
}
#end

iAd Banner implementation on Game Over Class

So I have a game that has a game over class. I also have an iAd banner at the bottom of the screen, but it stays there for the entire length of the game. I want the banner to appear when the game ends, and disappear when the user presses the restart game button.
In my RootViewController.mm I have the following code
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0,self.view.frame.size.height - 50, 320, 50)];
[self.view addSubview:adView];
}
How would I go about only displaying an iAd banner when the game ends?
You should create a Shared iAd Banner in your AppDelegate and then present the ADBannerView on which ever ViewController you like. This implementation takes into account that an ADBannerView will not always receive an ad from the iAd network. The ADBannerView's alpha property is set depending on whether it receives an ad or not using the ADBannerView's delegate methods. This way, you can just display and hide the ADBannerView when the game ends and when you reset it knowing that the ADBannerView will only be visible if it has an ad to present.
AppDelegate.h
#import <UIKit/UIKit.h>
#import iAd; // Import iAd
#interface AppDelegate : UIResponder <UIApplicationDelegate, ADBannerViewDelegate> // Include delegate
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ADBannerView *adView;
AppDelegate.m
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create our one ADBannerView
_adView = [[ADBannerView alloc]init];
// Set delegate and hide banner initially
_adView.delegate = self;
_adView.hidden = YES;
return YES;
}
// iAd delegate methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(#"bannerViewDidLoadAd");
_adView.alpha = 1.0;
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(#"didFailToReceiveAdWithError: %#",error);
_adView.alpha = 0.0;
}
ViewController.m
#import "ViewController.h"
#import "AppDelegate.h"
#interface ViewController () {
AppDelegate *appDelegate;
}
#end
#implementation ViewController
-(void)viewDidLoad {
[super viewDidLoad];
// Create reference to our app delegate
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// Position
appDelegate.adView.center = CGPointMake(self.view.center.x,
self.view.frame.size.height - appDelegate.adView.frame.size.height / 2);
// Add to view
[self.view addSubview:appDelegate.adView];
// I'm just calling the gameOver function for example
// You should add the contents of the function to something more suitable
[self gameOver];
}
-(void)gameOver {
// Unhide the ADBannerView in which ever function is called first in the gameover view
// I'm guessing you have a UIButton that this would work in
appDelegate.adView.hidden = NO;
}
-(void)gameReset {
// When you reset the game hide the ADBannerView
// I'm guessing you have a UIButton that this would work in also
appDelegate.adView.hidden = YES;
}
You can try this bit of code:
When your game ends: [self showiAdBanner];
When your game begins: [self hideiAdBanner];
If you use this code, you'll want to replace this:
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0,self.view.frame.size.height - 50, 320, 50)];
[self.view addSubview:adView];
with this:
[self showiAdBanner];
Two methods to show iad and hide iad:
- (void)showiAdBanner {
if( !_adView ) { // only add to view if it's not already there
_adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)]; //initialize it
_adView.delegate = self; // set delegate
}
_adView.hidden = NO; //reveal it
_bannerIsVisible = YES; //set bool to yes
}
- (void)hideiAdBanner {
_adView.hidden = YES; //hide it
_bannerIsVisible = NO; // set bool to no
}
Remember to add this part as well:
#interface RootViewController () <ADBannerViewDelegate>
#property (nonatomic, strong) ADBannerView *adView;
#property (nonatomic) BOOL bannerIsVisible;
#end
If you want to get fancy, instead of hiding it, you can animate/fade it out.

How to hide google ads in Objective c

In my project , i have implemented Google-Mobile-Ads SDK. I have followed all the steps with are written in the google site. I am able to access the google ad in all my view controllers as i have coded it in my AppDelegate.
Now , i want it to hide it from the first view controller (like we can hide navigationbar), how to implement this ?
In have coded this for google ads in AppDelegate`s DidFinishLaunchingMethod:-
bannerView=[[GADBannerView alloc] initWithFrame:CGRectMake(0, self.window.frame.size.height-50, self.window.frame.size.width, 50)];
[self.window addSubview:bannerView];
bannerView.adUnitID = #"ca-app-pub-8809802355107737/4999307809";
bannerView.rootViewController = self.window.rootViewController;
bannerView.delegate=self;
GADRequest *request = [GADRequest request];
request.testDevices = #[ #"eba07768136b615eee7c1f8acde25c1b",kGADSimulatorID ];
[bannerView loadRequest:request];
[self.window makeKeyAndVisible];
return YES;
I have this method also in appDelegate class :-
- (void)adViewDidReceiveAd:(GADBannerView *)view;
{
if (container.view.frame.size.height==self.window.frame.size.height-50) {
}
else
{
CGRect navFrame = container.view.frame;
navFrame.size.height -= 50;
container.view.frame = navFrame;
}
NSLog(#"asdhaskda");
}
in firstViewController:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:#"HIDEBANNER" object:nil];
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:#"SHOWBANNER" object:nil];
}
In AppDelegate.m file, in didFinishLaunchingWithOptions:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(hideBanner) name:#"HIDEBANNER" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showBanner) name:#"SHOWBANNER" object:nil];
Also implement those 2 functions. I'm not sure what exactly must be in those functions. Maybe something like this:
-(void)showBanner{
[bannerView setHidden:NO];
//this is from your code
if (container.view.frame.size.height==self.window.frame.size.height-50) {
}
else
{
CGRect navFrame = container.view.frame;
navFrame.size.height -= 50;
container.view.frame = navFrame;
}
}
-(void)hideBanner{
[bannerView setHidden:YES];
CGRect navFrame = container.view.frame;
navFrame.size.height = self.window.frame.size.height;
container.view.frame = navFrame;
}
There are many methods to do that. You can use, for example, NSNotificationCenter.
In your AppDelegate.m file in didFinishLaunchingWithOptions function:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(hideBanner) name:#"HIDEBANNER" object:nil];
Also in AppDelegate.m add the following function:
-(void)hideBanner{
[bannerView setHidden:YES];
}
And somewhere in you project, when you need to hide banner just call this:
[[NSNotificationCenter defaultCenter] postNotificationName:#"HIDEBANNER" object:nil];
AdMob Integration Full Code.
AppDelegate.h
// Write This Code in AppDelegate.h File Start
#import GoogleMobileAds;
#pragma mark - Admob
#property (strong, nonatomic) GADBannerView *bannerView;
-(void)loadAdmob:(UIViewController *)vc;
// End
AppDelegate.m
// Write This Code in AppDelegate.m File Start
#pragma mark - Admob Methods
-(void)loadAdmob:(UIViewController *)vc{
self.bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0, vc.view.frame.size.height-kBannerHeight, vc.view.frame.size.width, kBannerHeight)];
[vc.view addSubview:self.bannerView];
self.bannerView.hidden = YES;
//### Load Banner Ad view #####
// Replace this ad unit ID with your own ad unit ID.
self.bannerView.adUnitID = #"ca-app-pub-####"; // Botttom banner
self.bannerView.rootViewController = vc;
GADRequest *request = [GADRequest request];
// Requests test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made.
#ifdef DEBUG
request.testDevices = #[kGADSimulatorID];
//[Note: Comment this line for release build]
#endif
[self.bannerView loadRequest:request];
}
// Add this code in Viewcontroller.m file
[APP_DELEGATE loadAdmob:self];
// Add this line in PrefixHeader.pch
#define APP_DELEGATE (AppDelegate*)[[UIApplication sharedApplication] delegate]
#define kBannerHeight (IS_IPAD ? 65.0 : 49.0)

Communicating between Two Layers in a Scene Cocos2d 3

I have two layers set up like so in one scene:
header file for scene:
#interface GameScene1 : CCScene {
GameLayer *gameLayer;
HUDLayer *hudLayer;
}
Main file for scene:
-(id)init {
self = [super init];
if (self != nil) {
gameLayer = [GameLayer node];
[self addChild:gameLayer];
hudLayer = [HUDLayer node];
[self addChild:hudLayer];
}
return self;
}
HUD layer header:
#interface HUDLayer : CCNode {
CCSprite *background;
CGSize screenSize;
}
-(void)updateMonstersSlayed:(NSString*)value;
HUD layer main:
#implementation HudLayer
-(id)init
{
self = [super init];
if (self)
{
CGSize viewSize = [[CCDirector sharedDirector] viewSize];
monstersSlayed = [CCLabelTTF labelWithString:#"Monsters Killed: 0" fontName:#"Arial" fontSize:15];
monstersSlayed.position = ccp(viewSize.width * 0.85, viewSize.height * 0.1 );
[self addChild:monstersSlayed];
}
return self;
}
-(void)updateMonstersSlayed:(NSString*)value
{
monstersSlayed.string = value;
}
Game Layer main
- (BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair collisionPlayer:(CCNode *)user collisionMonster:(CCNode *)monster
{
if (holdingWeapon)
{
HudLayer *myHud = [[HudLayer alloc] init];
[myHud updateMonstersSlayed:#"Monsters Killed: 1"];
}
}
Simply trying to get it set to where I can set text from the Game Layer to show up in a Label in the Hud Layer.
How would I accomplish this in Cocos2d 3?
There are many ways you can do this. But for the sake of simplicity the easiest way you can do this is via notifications. For example in the hud add:
#implementation HudLayer
- (void)onEnter
{
[super onEnter];
NSNotificationCenter* notiCenter = [NSNotificationCenter defaultCenter];
[notiCenter addObserver:self
selector:#selector(onUpdateMonsterText:)
name:#"HudLayerUpdateMonsterTextNotification"
object:nil];
}
- (void)onExit
{
[super onExit];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)onUpdateMonsterText:(NSNotification *)notification
{
NSDictionary* userInfo = notification.userInfo;
if (userInfo)
{
NSString* text = userInfo[#"text"];
if (text)
{
[self updateMonstersSlayed:text];
}
else
{
CCLOG(#"Monster hud text param is invalid!.");
}
}
else
{
CCLOG(#"Monster hud user info invalid!");
}
}
#end
Then anywhere in your application where you want to update text you can just post the notification. Using your physics collision began example:
- (BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair
*emphasized text*collisionPlayer:(CCNode *)user collisionMonster:(CCNode *)monster
{
if (holdingWeapon)
{
NSDictionary* userInfo = #{#"text" : #"Monsters Killed: 1"};
NSString* notiName = #"HudLayerUpdateMonsterTextNotification";
[[NSNotificationCenter defaultCenter] postNotificationName:notiName
object:self userInfo:userInfo];
}
}
Hope this helps.
You can use methods. Make a method in HUD layer class.
-(void) giveMeMyText:(NSString*)someText
{
do something with my someText
}
Don't forget to make the method visible in HUD.h -(void) giveMeMyText; Then import HUD layer class in GameScene1 #import "HUDlayer.h" and use it.
HUDLayer* myHud = [[HUDLayer alloc] init];
[myHud giveMeMyText:#"say hi!"];
You could use delegation, so your scene would implement GameLayerProtocol and the delegate of GameLayer. That way the scene would be notified of any changes the GameLayer has and act appropriately on the HudLayer.
For example:
// GameLayer class
#protocol GameLayerProtocol <NSObject>
- (void)someThingHappenedInGameLayer;
#end
#interface GameLayer : CCNode
#property (nonatomic, weak) id<GameLayerProtocol> delegate;
#end
#implementation GameLayer
- (void)someActionInGameLayer
{
[self.delegate someThingHappenedInGameLayer];
}
#end
// Scene class
#interface IntroScene : CCScene <GameLayerProtocol>
#end
#implementation IntroScene
// Implement protocol methods
- (void)someThingHappenedInGameLayer
{
//Do something with your HUDLayer here
}
#end

Hide/Show iAds in Spritekit

I've been trying to figure out how to hide and show iAds in my Spritekit Scenes. Currently I have it setup like this:
ViewController.h
#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>
#import <iAd/iAD.h>
#interface ViewController : UIViewController <ADBannerViewDelegate> {
ADBannerView *adView;
}
-(void)showsBanner;
-(void)hidesBanner;
#end
ViewController.m
#import "ViewController.h"
#import <UIKit/UIKit.h>
#import <iAd/iAD.h>
#import "MyScene.h"
#import <SpriteKit/SpriteKit.h>
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = NO;
skView.showsNodeCount = NO;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
self.canDisplayBannerAds = YES;
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 0.0f);
adView.delegate=self;
[self.view addSubview:adView];
self.bannerIsVisible=NO;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, 0.0);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, 0.0);
[adView setAlpha:0];
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
-(void)hidesBanner {
NSLog(#"HIDING BANNER");
[adView setAlpha:0];
self.bannerIsVisible = NO;
}
-(void)showsBanner {
NSLog(#"SHOWING BANNER");
[adView setAlpha:1];
self.bannerIsVisible = YES;
}
etc...
#end
Then in my scene I grab my viewcontroller with a pointer:
ViewController *controller;
controller = [[ViewController alloc] init];
[controller hidesBanner];
My nslog runs in the console so I know it's going through. But the banner won't hide. Any thoughts? I'm pretty new with objective c so I have a feeling I'm just doing something dumb.
Like Huygamer said, you're creating a new instance of a view controller so when you call your method [controller hidesBanner]; you're referring to another object.
The best approach here is to use NSNotificationCenter: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsnotificationcenter_Class/Reference/Reference.html
And send a message to your viewcontroller whenever you want to hide or show your ad:
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
//Add view controller as observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleNotification:) name:#"hideAd" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleNotification:) name:#"showAd" object:nil];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = NO;
skView.showsNodeCount = NO;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
self.canDisplayBannerAds = YES;
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 0.0f);
adView.delegate=self;
[self.view addSubview:adView];
self.bannerIsVisible=NO;
}
//Handle Notification
- (void)handleNotification:(NSNotification *)notification
{
if ([notification.name isEqualToString:#"hideAd"]) {
[self hidesBanner];
}else if ([notification.name isEqualToString:#"showAd"]) {
[self showBanner];
}
}
And in your scene:
[[NSNotificationCenter defaultCenter] postNotificationName:#"showAd" object:nil]; //Sends message to viewcontroller to show ad.
[[NSNotificationCenter defaultCenter] postNotificationName:#"hideAd" object:nil]; //Sends message to viewcontroller to hide ad.
Of course, there are 2 object and why you think it can do?
If you want to access the parent of skscene just do this
UIViewController *vc = self.view.window.rootViewController;
You can access the parent of this skscene and you can do hideBanner at the parent of this scene. Simple?
Here is what I did to make it work with SpriteKit Scenes (Xcode 6.1 and iOS 8.1 on iPhone 6):
Step 1- Add #import <"iAd/iAd.h"> in MyScene.h header file
Step 2- Make sure you declare your MyScene class to implement protocol in MyScene.h header file.
Step 3- Add the following code lines in your MyScene.m file inside -(Void)didMoveToView:(SKView *)view function.
ADBannerView* banner=[[ADBannerView alloc]initWithFrame:CGRectZero];
CGRect bannerFrame =CGRectMake(0, 667, self.view.frame.size.width, 0);
banner.frame=bannerFrame;
[self.view addSubview:banner];
banner.delegate=self;
Step 4- Implement the two methods of iAd
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
CGRect bannerFrame =CGRectMake(0, 667-50, self.view.frame.size.width, 0);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
banner.frame=bannerFrame;
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
CGRect bannerFrame =CGRectMake(0, 667, self.view.frame.size.width, 0);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
banner.frame=bannerFrame;
[UIView commitAnimations];
}
The above code will move the Ad frame to scene when there is an Ad and will remove the frame if no Ad by animating the movement. Note that the last number in the frame rect is 0. It doesn't matter what you put there, the banner hight is fixed and doesn't change (50 pt).
Step 5- Respond to Ad actions by this code:
-(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
[self startTimer];
}
-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
[gameTimer invalidate];
return YES;
}
This code will stop the game timer when a user clicks on the banner and resumes the game timer after the user returns back to the game. You can add your own code for saving and retrieving game data here.
Hope this helps.

Resources