Spritekit Interstitial Admob ios8

Я попытался проверить другие связанные вопросы, но безуспешно. Я следую коду примера, расположенному здесь. Программа успешно работает на моем 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]; 

person bolencki13    schedule 10.12.2014    source источник
comment
Как вы вызываете рекламу в skscene? Я должен увидеть ваши коды для помощи.   -  person Valar Morghulis    schedule 11.12.2014
comment
Вы не можете так звонить из SKScene. Попробуйте пример кода cocos2d, cocos2d уже доступен в вашем следующем примере.   -  person Valar Morghulis    schedule 11.12.2014


Ответы (2)


В вашем 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];
person Valar Morghulis    schedule 10.12.2014
comment
Он по-прежнему зависает на начальном этапе self.interstitial = [[GADInterstitial alloc] init]; останавливает программу - person bolencki13; 11.12.2014
comment
Вы пробовали пример cocos2d? - person Valar Morghulis; 11.12.2014
comment
У меня есть вызов методов, но теперь каждый раз, когда он отображает баннер, он не готов к показу. - person bolencki13; 11.12.2014
comment
тестовое объявление отображается на симуляторе, но вместо этого на моем телефоне отображается предупреждение. Любая причина, почему? - person bolencki13; 11.12.2014
comment
Потратил еще час, работая над этим. Телефон завис, поэтому я перезагрузился, и теперь он работает. Спасибо! - person bolencki13; 11.12.2014

Вы забыли добавить -ObjC к Linker

Ниже приведено решение:

  1. Нажмите на название вашего проекта

  2. Перейдите на вкладку «Настройки сборки».

  3. Найдите имя linker

  4. Найти другие флаги ссылок

  5. Дважды щелкните имя вашего проекта, затем нажмите + button.

  6. добавить -ObjC

person Luke    schedule 21.01.2015