我试过检查其他相关问题,但没有成功。我遵循位于这里的示例代码。程序成功地在我的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]; 发布于 2014-12-10 23:44:30
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];发布于 2015-01-21 03:16:57
您忘了将-ObjC添加到Linker
以下是解决办法:
linker+ button-ObjChttps://stackoverflow.com/questions/27412355
复制相似问题