Search code examples
objective-csprite-kitadsrevmob

Ads not working properly


The following is code in my Appdelegate.m class:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[RevMobAds startSessionWithAppID:@"Id"];

// Override point for customization after application launch.
return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{ 

[[RevMobAds session] showBanner];

}

The following is code in my ViewController.h class:

@interface ViewController : UIViewController<RevMobAdsDelegate>

@property ( nonatomic, strong)RevMobBanner *bannerWindow;

The following is code in my ViewController.m class:

- (void)handleNotification:(NSNotification *)notification
{
if ([notification.name isEqualToString:@"showAd"])
{
    _bannerWindow = [[RevMobAds session] banner];
    [_bannerWindow showAd];
}
}

//RevMob required delegate method
 -(void) revmobAdDidFailWithError:(NSError *)error {
NSLog(@"[RevMob sample app] Ad failed: %@", error);
}

//revmob optional delegate method
-(void) revmobAdDidReceive {
NSLog(@"[RevMob sample app] ad loaded.");
} 

-(void) revmobAdDisplayed {
NSLog(@"[RevMob sample app] ad displayed.");
}

-(void) revmobUserClosedTheAd {
NSLog(@"[RevMob sample app] user clicked in the close button.");
}

-(void) revmobUserClickedInTheAd {
NSLog(@"[RevMob sample app] user clicked in the ad.");
} 

-(void) installDidReceive {
NSLog(@"[RevMob sample app] install did recieve.");
}

-(void) installDidFail{
NSLog(@"[RevMob sample app] install did fail.");
}

- (void)viewDidLoad
{
 [super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];
}

The following is code in MyScene.m (my main menu) class:

-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
    self.backgroundColor = [SKColor colorWithRed:(29.0f/255) green:(29.0f/255) blue:(29.0f/255) alpha:1.0];





    [[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil];
    }
return self;
}

Solution

  • I am using this method in StartApp. Try this.

    //yourViewControl.m
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];
    
    - (void)handleNotification:(NSNotification *)notification
    {
        if ([notification.name isEqualToString:@"showAd"]) 
        {
            [[RevMobAds session] showBanner];
        }
    }
    
    //yourSKScene
    
        [[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil];//Call with this.