ios - 使用 iAd 展示广告,不使用 Storyboard 或 Xib

标签 ios objective-c iad

我一直在尝试在不使用 Storyboard或 Xib 文件的情况下使横幅广告出现在我的应用程序的底部。遗憾的是,这是行不通的。我已经尝试按照教程进行操作,只是没有添加 Storyboard ,但无济于事。我的项目编译正常,但广告没有显示在模拟器的底部,也没有显示在任何地方。这是我的 viewcontroller.mm 代码的相关示例:

@implementation ViewController
{
    ADBannerView *_bannerView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:(_bannerView)];
    self.canDisplayBannerAds = true;

}

header 导入,包含 iAd.framework。标题也有此修改行 @interface ViewController : UIViewController <ADBannerViewDelegate>

最佳答案

您没有初始化 bannerView,如果您不初始化它,就像任何其他 UI 对象一样,您将看不到任何东西。因此首先对其进行初始化,然后将其添加到 View 中并启用 canDisplayBannerAds 以防止出现任何错误。

@implementation ViewController{
ADBannerView *_bannerView; }

- (void)viewDidLoad{
[super viewDidLoad];
 self.canDisplayBannerAds = true;
 //_bannerView = [[ADBannerView alloc]initWithFrame:CGRectMake(0,0,320,50)];

//Instead of giving the position when initializing, give the AdType
        bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];

//Then give the position
        [view setFrame:CGRectMake(0, 0, 320, 50)];

[self.view addSubview:(_bannerView)];

}

如@Christophr 所说,还要在 iOS 测试设备上启用 iAd 填充率。

那应该行得通。 希望对您有所帮助。

关于ios - 使用 iAd 展示广告,不使用 Storyboard 或 Xib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30688857/

相关文章:

ios - 无法在 Safari 中检查我的调试版本

ios - 在 UIScrollView 中设置 UIViews 框架后未调用 UIGestureRecognizer

ios - 将它添加到数组(dict)时如何自动将 nil 转换为 [NSNull null]?

ios - 新的 iAd 在 iOS 6 中崩溃

ios - 在 UIWebView 中显示多页 PDF(无抖动): How does Safari do it?

iOS NSURLAuthenticationMethodClientCertificate 未请求与 ActiveSync 服务器

ios - ADBannerView 未显示

ios - 从一个场景中删除 iAd 横幅

ios10 swift 3核心聚光灯搜索无法获得nsuseractivity的标题

ios - setAttributedText 不适用于 UIButton?