簡體   English   中英

測試iAd效果不錯,但實時iAd失敗

[英]Test iAds are good, but live iAds fail

當我的應用程序開發時,iAds運作良好。 每隔30秒,我要么會調用“ bannerViewDidLoadAd”,要么會調用“ didFailToReceiveAdWithError”,並且我准備了應用程序來處理任一回調。 我得到綠色的對號“您已連接到iAd的應用程序網絡”和其他測試廣告。

現在,該應用程序已投入使用,僅會顯示“ didFailToReceiveAdWithError”,而不會加載任何廣告。 我正在插入Xcode Organizer Console的手機上運行該應用程序的發行版,並且看到在“ didFailToReceiveAdWithError”中打印的NSLog。

iAd Portal雖然未顯示任何請求,但列出了0個請求。

我已經使用開發配置文件從XCode再次將其構建到我的手機中,並且再次可以正常工作。 我已經刪除了該應用程序,關閉了手機,退出了iTunes Apple ID,然后從App Store重新下載了該應用程序,但每次廣告仍然失敗。

廣告的編碼方式如下:

在我的rootViewController中,用戶選擇開始一個新游戲,然后為新視圖設置動畫:

    UIViewController *nextController = [[GamePlayViewController alloc] initWithNibName:@"GamePlayView" bundle:nil];
    [nextController performSelector:@selector(setDelegate:) withObject:self];

    nextController.view.frame = CGRectMake(0, 570, 320, 568);
    [self.view addSubview:nextController.view];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.23];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    nextController.view.frame = CGRectMake(0, 0, 320, 568);

    [UIView commitAnimations];

    temporaryController = nextController;

GamePlayViewController.h包括:

 - #import <iAd/iAd.h>
 - @interface GamePlayViewController : UIViewController <ADBannerViewDelegate, UIDocumentInteractionControllerDelegate> {

GamePlayViewController.m包括:

 - ADBannerView *_bannerView;

一旦用戶進入GamePlayViewController.m,viewDidLoad中就會觸發一個動畫,並且一旦該動畫完成,就會調用一個廣告:

if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
        _bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
    } else {
        _bannerView = [[ADBannerView alloc] init];
    }
    _bannerView.delegate = self;

    [self.view bringSubviewToFront:_bannerView];
}

除了iAd的回調方法外,這實際上就是所有這些。

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"ad loaded!");

    _bannerView.hidden = NO;
    [self layoutAnimated:YES];
}

- (void)layoutAnimated:(BOOL)animated
{
    // As of iOS 6.0, the banner will automatically resize itself based on its width.
    // To support iOS 5.0 however, we continue to set the currentContentSizeIdentifier appropriately.
    CGRect contentFrame = self.view.bounds;
    if (contentFrame.size.width < contentFrame.size.height) {
        _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

    CGRect bannerFrame = _bannerView.frame;
    if (_bannerView.bannerLoaded) {
        bannerFrame.origin.y = 0;
    } else {
        bannerFrame.origin.y = contentFrame.size.height;
    }


    [UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
        _contentView.frame = contentFrame;
        [_contentView layoutIfNeeded];
        _bannerView.frame = bannerFrame;
        [self.view addSubview:_bannerView];
    }];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"ad failed!");
    _bannerView.hidden = YES;
}

也許我正在做的事情是錯誤的,或者我應該在rootViewController上放置廣告,但是此代碼可與測試iAd一起很好地工作,因此我不確定為什么它不能與該應用的App Store版本一起使用。

謝謝你的幫助!

我沒有看過您的代碼,但我也看到了。 有時,Apple只是沒有出售任何廣告,因此沒有任何廣告可以顯示給您。 考慮使用廣告聚合器。 我使用https://github.com/larsacus/LARSAdController,但對其進行了修改,以按照我想要的方式顯示廣告。

我在博客條目中對此進行了介紹: http : //www.notthepainter.com/iad-admob-integration-with-a-dynamic-uiview/


這是博客條目的文本,因此保留在此處,以防萬一我的博客消失了。


我已經發布了兩個都與iAds結合的應用程序。 我使用Apple的BannerView示例代碼來實現此目的。 基本上,在您的委托中,您無需將root設置為期望的根UIViewController,而是將root設置為包含真實根的BannerView。 如果有iAd,則主視圖會縮小,並且iAd會顯示在底部。 當廣告不可用時,您的視圖將擴展為“正常”尺寸。

這在測試中效果很好,因此我將兩個應用程序都發布到了應用程序商店。 他們做完了嗎? 和惠林。 但是,當我第一次從商店下載版本時,我很驚訝沒有看到任何廣告。 事實證明,至少現在,iAd的填充率非常糟糕。 因此,我想在iAd不可用時展示另一個廣告。

我在GitHub上找到了Larsacus的開源項目LARSAdController。 除了一件事情,他使廣告集成非常容易。 當您沿他的快速開發路線前進時,您會得到覆蓋您視圖的廣告,但不會縮小以容納廣告。 這是一個完全合理的設計決定,而並非我想要的。

因此,我決定修改Apple的BannerView以使用LARSAdController。 這很容易。

您要做的第一件事是從BannerView的.h文件和LARS TOLAdViewController類中的廣告中刪除iAd。

#import "TOLAdViewController.h"

#define KVO_AD_VISIBLE @"KVO_AD_VISIBLE"

@interface BannerViewController : TOLAdViewController

(現在暫時忽略KVO_AD_VISIBLE定義,我將在后面介紹。)在.m文件中,還刪除iAd並進行以下更改:

@implementation BannerViewController {
    UIView *_bannerView;
    UIViewController *_contentController;
    BOOL isLoaded;
}

我們將_bannerView從ADBannerView更改為普通的舊版UIVIew。 ADBannerView還具有bannerLoaded屬性,我們必須將其替換為isLoaded布爾值。 initWithContentViewController也很容易修改。

// IAPHelper *sharedInstance = [//IAPHelper sharedInstance];
//if ([sharedInstance showBannerAds]) {
if (YES) {
    _bannerView = [[UIView alloc] initWithFrame:CGRectZero];
} else {
    _bannerView = nil;      // not showing ads since the user has upgraded
}

注意注釋掉的部分。 如果您使用應用內購買功能將受廣告支持的版本轉換為無廣告版本,則可以在那里進行操作。

在該方法的最后,請很好地使用鍵值觀察(KVO)來觀看LARS並查看何時投放或移除廣告。 (我可能會在以后的博客文章中介紹KVO。)

[[LARSAdController sharedManager] addObserver:self
                                   forKeyPath:kLARSAdObserverKeyPathIsAdVisible
                                      options:0
                                      context:KVO_AD_VISIBLE];

並觀察代碼:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context;
{
    if(context == KVO_AD_VISIBLE) {
        NSNumber *isVisible = [object valueForKey:kLARSAdObserverKeyPathIsAdVisible];

        if ([isVisible boolValue]) {
            _bannerView.frame = [[LARSAdController sharedManager] containerView].frame;
            isLoaded = YES;
        } else {
            isLoaded = NO;
        }
    }

    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];
}

我們保存新廣告的框架,並更新isLoaded變量。 (本來以為我需要調用setNeedsLayout和layoutIfNeeded,但實際上我沒有。)viewDidLayoutSubviews的模塊也非常簡單。 唯一奇怪的部分是刪除了對ADBannerContentSizeIdentifierPortrait和ADBannerContentSizeIdentifierLandscape的引用,並將它們全部替換為一行:

bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];

幾行之后,您使用新的isLoaded變量

if (isLoaded) {

不要忘記在dealloc中清理觀察者:

-(void) dealloc;
{
    [[LARSAdController sharedManager]  removeObserver:self forKeyPath:kLARSAdObserverKeyPathIsAdVisible];
}

剩下的就是在應用程序委托中向LARS告知您的廣告:

[[LARSAdController sharedManager] registerAdClass:[TOLAdAdapterGoogleAds class] withPublisherId:@"a14e55c99c24b43"];
[[LARSAdController sharedManager] registerAdClass:[TOLAdAdapteriAds class]];

LARSBannerViewController *root = [[LARSBannerViewController alloc] initWithNibName:@"LARSBannerViewController" bundle:nil];

_bannerViewController = [[BannerViewController alloc] initWithContentViewController:root];

[self.window setRootViewController:_bannerViewController];

就是這樣。 現在,您的應用應顯示iAD或AdMob廣告,並且您的視圖將縮小以適應它們。

當然,這里有一個錯誤,我不知道這是在AdMob服務器中還是在LARS中,但是當您在iPhone上處於橫向模式時,廣告的大小和報告的大小會有所不同,在屏幕底部留下一個黑條。 我已經對larsacus進行了查詢,並在我了解更多信息時更新了此信息。

我分叉了LARSAdController,並在我的github上的一個完整項目中提交了上面的示例代碼。

幾天后,我准備尋求支持,然后iAds開始工作。 因此,我想答案是,在應用上線與為該應用填充廣告之間可能會出現延遲。

最初,當廣告開始出現時,填充率並沒有超過50%,我只看到iTunes Radio的一個廣告,但至少這些廣告已經開始運作了。 現在,填充率高達67%,我看到的廣告種類更多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM