2014-12-10 50 views
0

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

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]; 
+0

你如何在skscene叫广告?我必须看到你的代码寻求帮助。 – 2014-12-10 23:19:57

+0

你不能从SKScene这样调用。尝试使用cocos2d示例代码,在以下示例中已经可以使用cocos2d。 – 2014-12-10 23:29:21

回答

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

yourSKScene通话与this

[[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil]; 
+0

它仍然挂在最初的self.interstitial = [[GADInterstitial alloc] init];停止程序 – bolencki13 2014-12-10 23:51:15

+0

你试过cocos2d的例子吗? – 2014-12-10 23:52:16

+0

我已经调用了方法,但现在每一次它显示的横幅都没有准备好显示。 – bolencki13 2014-12-11 00:25:21

1

你忘了添加-ObjCLinker

下面是解决方案:

  1. 点击项目名称

  2. 去盖设置选项卡

  3. 搜索名称linker

  4. Fin d。其他链接标志

  5. 您的项目名称,双击然后单击+ button

  6. 添加-ObjC