广告无法正常运作

时间:2014-12-10 11:30:32

标签: objective-c sprite-kit ads revmob

以下是我的Appdelegate.m类中的代码:

- (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];

}

以下是我的ViewController.h类中的代码:

@interface ViewController : UIViewController<RevMobAdsDelegate>

@property ( nonatomic, strong)RevMobBanner *bannerWindow;

以下是我的ViewController.m类中的代码:

- (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];
}

以下是MyScene.m(我的主菜单)类中的代码:

-(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;
}

1 个答案:

答案 0 :(得分:0)

我在StartApp中使用此方法。试试这个。

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