首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spritekit Interstitial ios8

Spritekit Interstitial ios8
EN

Stack Overflow用户
提问于 2014-12-10 22:51:56
回答 2查看 449关注 0票数 0

我试过检查其他相关问题,但没有成功。我遵循位于这里的示例代码。程序成功地在我的iPhone上运行,但是当我第一次调用广告时,它会挂在self.interstitial = [GADInterstitial alloc init]上。没有错误消息,它只是停止运行,上面的行高亮显示。我已经尝试在GameViewController和实际的精灵工具包中运行它。任何帮助都将不胜感激。我下载的示例项目运行得很好。

GameViewController.h

代码语言:javascript
复制
@property (strong,nonatomic) GADInterstitial *interstitial;
-(void)createAndLoadInterstitial;
-(void)loadAd;

GameViewController.m

代码语言:javascript
复制
- (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];

}

代码语言:javascript
复制
-(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

代码语言:javascript
复制
@property (nonatomic, strong) GameViewController *GameViewController;

GameScene.m

代码语言:javascript
复制
//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]; 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-10 23:44:30

ViewController中的

代码语言:javascript
复制
[[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的调用中的

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil];
票数 0
EN

Stack Overflow用户

发布于 2015-01-21 03:16:57

您忘了将-ObjC添加到Linker

以下是解决办法:

  1. 点击您的项目名称
  2. 转到“生成设置”选项卡
  3. 搜索名称linker
  4. 查找其他链接标志
  5. 双击项目名称,然后单击+ button
  6. 添加-ObjC
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27412355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档