Spritekit Intertitial Admob ios8

时间:2014-12-10 22:51:57

标签: ios8 sprite-kit admob interstitial

我已尝试检查其他相关问题,但未成功。我正在关注位于here的示例代码。该程序在我的iPhone上成功运行,但是当我第一次打电话给广告时,它会挂在self.interstitial = [[GADInterstitial alloc] init]上; 。没有错误消息,只是突出显示上面的行停止运行。我试过在GameViewController和我的实际精灵套件场景中运行它。任何帮助,将不胜感激。我下载的示例项目运行完美。

GameViewController.h

@property (strong,nonatomic) GADInterstitial *interstitial;
-(void)createAndLoadInterstitial;
-(void)loadAd;

GameViewController.m

- (void)createAndLoadInterstitial {
self.interstitial = [[GADInterstitial alloc] init];
self.interstitial.adUnitID = @"ca-app-pub-9726509502990875/8489925949";
self.interstitial.delegate = self;

GADRequest *request = [GADRequest request];
// Request test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made.
request.testDevices = @[ GAD_SIMULATOR_ID, @"MY_TEST_DEVICE_ID" ];
[self.interstitial loadRequest:request];

}

-(void)loadAd {
if (self.interstitial.isReady) {
    [self.interstitial presentFromRootViewController:self];
} else {
    [[[UIAlertView alloc] initWithTitle:@"Interstitial not ready"
                                message:@"The interstitial didn't finish loading or failed to load"
                               delegate:self
                      cancelButtonTitle:@"Drat"
                      otherButtonTitles:nil] show];
}

}

GameScene.h

@property (nonatomic, strong) GameViewController *GameViewController;

GameScene.m

//this is in -(void)gameOver which is called on contact call in -(void)didBeginContact
self.GameViewController = [[GameViewController alloc] init];
[self.GameViewController createAndLoadInterstitial];
[self.GameViewController loadAd]; 

2 个答案:

答案 0 :(得分:1)

您忘记将-ObjC添加到Linker

以下是解决方案:

  1. 点击您的项目名称

  2. 转到“构建设置”选项卡

  3. 搜索名称linker

  4. 查找其他链接标志

  5. 双击项目名称,然后点击+ button

  6. 添加-ObjC

答案 1 :(得分:0)

ViewController

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

- (void)handleNotification:(NSNotification *)notification
{
    if ([notification.name isEqualToString:@"showAd"]) {
        if (self.interstitial.isReady) {
           [ self.interstitial presentFromRootViewController:self];
        } else {
            [[[UIAlertView alloc] initWithTitle:@"Interstitial not ready"
                                message:@"The interstitial didn't finish loading or failed to load"
                               delegate:self
                      cancelButtonTitle:@"Drat"
                      otherButtonTitles:nil] show];
        }
    }
}

yourSKScenethis

进行通话
[[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil];