gpt4 book ai didi

ios - 我无法在我的应用程序中查看 iAds

转载 作者:行者123 更新时间:2023-11-29 03:10:20 24 4
gpt4 key购买 nike

在viewcontroller.m中

#import "ViewController.h"
#import "MyScene.h"

@import AVFoundation;

@interface ViewController ()
@property (nonatomic) AVAudioPlayer * backgroundMusicPlayer;
@end

@implementation ViewController

- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
NSError *error;
NSURL * backgroundMusicURL = [[NSBundle mainBundle] URLForResource:@"loop" withExtension:@"wav"];
self.backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:&error];
self.backgroundMusicPlayer.numberOfLoops = 1;
[self.backgroundMusicPlayer prepareToPlay];
[self.backgroundMusicPlayer play];

// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
skView.showsFPS = YES;
skView.showsNodeCount = NO;

// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;





// Present the scene.
[skView presentScene:scene];

self.canDisplayBannerAds = YES;

}
}
- (BOOL)shouldAutorotate
{
return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}

}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
@end

在viewcontroller.m中

#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>
#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate>

@end

在appDelegate.h中

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate, ADBannerViewDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

我根本无法查看我的 iAd。

我觉得我错过了什么,但我无法解决。

我的应用/游戏运行完美,但无法显示 iAds。

我正在使用的文件是

appDelegate.h 
appDelegate.m
main storyboard
viewController.h
viewController.m
myScene.h
myScene.m
main.m
GAME-prefix.pch
gameOverScene.h
gameOverScene.m

最佳答案

看起来你实际上并没有在任何地方实现 iAd 横幅方法......你可以像这样使用它们:

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
//user has internet connection, show the iAd

CGRect bannerFrame = banner.frame;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIViewController *ViewController;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1]; //animate the ad in
[banner setAlpha:1]; //show the banner add
[UIView commitAnimations];
}



- (void)bannerView:(ADBannerView *) banner didFailToReceiveAdWithError:error{
//banner view could not be loaded
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1]; //animate the ad out
[banner setAlpha:0]; //do not show the ad
[UIView commitAnimations];
}

您可以将其放入您的根 ViewController 文件中,然后只需将一个 ADBannerView 拖到您的 storyboard View 中。然后右键单击 ADBannerView,在 Outlets 下,将 delegate 连接到您的 File's Owner,或者小黄在 View 底部圈出:

enter image description here

之后,当有互联网连接时,广告应该会正确显示。

关于ios - 我无法在我的应用程序中查看 iAds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22315855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com