LoginSignup
9
8

More than 5 years have passed since last update.

AdMobメディエーション,nend導入手順(Admob6.8.0,nend2.3.2)

Last updated at Posted at 2014-02-20

下準備

1,フレームワークの追加

・AVFoundation
・StoreKit
・CoreTelephony
・AudioToolbox
・MessageUI
・SystemConfiguration
・CoreGraphics
・AdSupport

コード

#import "GADBannerView.h"
@interface HogeViewController : UIViewController<GADBannerViewDelegate>

@interface HogeViewController ()
{
    GADBannerView* gadView;
    BOOL _bannerIsVisible;
}
@end

#pragma AD

/**
 * 画面を読み込む際の処理
 */
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initAd];
}

/**
 * Admobの広告を生成
 */
- (void)initAd{
    _bannerIsVisible = NO;

    // AdMob設定
    CGFloat adY = self.view.bounds.size.height - GAD_SIZE_320x50.height;
    CGRect bannerFrame = CGRectMake(0, adY, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height);

    gadView = [[GADBannerView alloc] initWithFrame:bannerFrame];
    gadView.adUnitID = ADMOB_MEDIATION;
    gadView.rootViewController = self;
    [self.view addSubview:gadView];

    gadView.delegate = self;

    GADRequest *request = [GADRequest request];
    request.testDevices = @[GAD_SIMULATOR_ID];//テストでインプレッションが発生しないようにシュミレータのIDを設定
    [gadView loadRequest:request];
}


/**
 * AdMob取得成功
 */
- (void)adViewDidReceiveAd:(GADBannerView *)view
{
    if (!_bannerIsVisible) {
        CGFloat adY = self.view.bounds.size.height - GAD_SIZE_320x50.height;
        CGRect bannerFrame = CGRectMake(0, adY, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height);

        [UIView animateWithDuration:0.3 animations:^{
            gadView.frame = bannerFrame;
        }];
        _bannerIsVisible = YES;
    }
}
/**
 * AdMob取得失敗
 */
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
{
    [gadView removeFromSuperview];
    gadView = nil;
}

参考サイト

AdMob SDK for iOS に必要な framework | CODE | NEO-SHOCKER.COM

Google AdMob Ads iOS(初級) - Google Mobile Ads SDK — Google Developers

【iPhoneアプリ】AdMobメディエーションを使ってiAd, AdMob, nendを併用してみた - 夏までにiPhone アプリつくってみっか!

nend2.3.2

・AdmobでnendのAPIkey spotkeyの追加(メディエーションを使用するなら)
・SDKをプロジェクトに追加
・メディエーション用のnendアダプター追加
・以下2つのフレームワークの追加
AdSupport.framework
Security.framework

nendアイコン型広告(サイズはデフォルトの75*75)


#import "NADIconLoader.h"

<NADIconLoaderDelegate>//デリゲート追加

@interface HogeViewController ()
{
    NADIconLoader *iconLoader;
    NADIconView *iconView1;
    NADIconView *iconView2;
    NADIconView *iconView3;
    NADIconView *iconView4;
}
@end


/**
 * nendの広告を生成
 */
- (void)initNend{
/*
    フッターに置く場合でメディエーションの上に配置する場合のY座標
    CGFloat adY = self.view.bounds.size.height - GAD_SIZE_320x50.height - 80; 
    iconView1 = [[NADIconView alloc] initWithFrame:CGRectMake(0, adY, 75, 75)];
    iconView2 = [[NADIconView alloc] initWithFrame:CGRectMake(80, adY, 75, 75)];
    iconView3 = [[NADIconView alloc] initWithFrame:CGRectMake(160, adY, 75, 75)];
    iconView4 = [[NADIconView alloc] initWithFrame:CGRectMake(240, adY, 75, 75)];
*/

    //ヘッダーに4つ並べる場合
    iconView1 = [[NADIconView alloc] initWithFrame:CGRectMake(0, 5, 75, 75)];
    iconView2 = [[NADIconView alloc] initWithFrame:CGRectMake(80, 5, 75, 75)];
    iconView3 = [[NADIconView alloc] initWithFrame:CGRectMake(160, 5, 75, 75)];
    iconView4 = [[NADIconView alloc] initWithFrame:CGRectMake(240, 5, 75, 75)];


    [self.view addSubview:iconView1];
    [self.view addSubview:iconView2];
    [self.view addSubview:iconView3];
    [self.view addSubview:iconView4];

    iconLoader = [NADIconLoader new];
    [iconLoader setIsOutputLog:YES];
    [iconLoader setDelegate:self];

    [iconLoader addIconView:iconView1];
    [iconLoader addIconView:iconView2];
    [iconLoader addIconView:iconView3];
    [iconLoader addIconView:iconView4];


#ifdef DEBUG //DEBUGなら検証用広告を読み込む&ログを吐く
    [iconLoader setIsOutputLog:YES];
    [iconLoader setNendID:NEND_TEST_ICON_ID spotID:NEND_TEST_ICON_SPOT];
#else
    [iconLoader setIsOutputLog:NO];
    [iconLoader setNendID:NEND_ICON_ID spotID:NEND_ICON_SPOT];
#endif

    [iconLoader load];
}

- (void)dealloc{//これを忘れるとnendが理由でクラッシュする
    [iconLoader setDelegate:nil];
    iconLoader = nil;
}
//本番
#define NEND_ICON_ID @"YOUR_NEND_APIKEY"
#define NEND_ICON_SPOT @"YOUR_NEND_SPOTID"

//検証用
#define NEND_TEST_ICON_ID @"2349edefe7c2742dfb9f434de23bc3c7ca55ad22"
#define NEND_TEST_ICON_SPOT @"101281"

メディエーションと併用するなら、nendの広告を読み込んでいる、initNendメソッドをinitAdメソッド内で、

[self initNend];

と書いて広告の生成をまとめておくと、アプリ内課金で広告非表示にする際に、ViewDidLoad内の

[self initAd];

の部分を読み込むかどうかの判定を入れるだけで、
広告をコントロールできるようになるので良いかもしれない。

SDKのバージョンが上がると、実装方法が変わる可能性が高いため
最新版のマニュアルにも目を通しておく事。
nend2.3.2マニュアル:nendSDK iOS 設定マニュアル - nendSDKiOS2.3.2_manual.pdf

nend検証用APIKEY & SPOTID

320x50
apikey:a6eca9dd074372c898dd1df549301f277c53f2b9
spotid:3172

320x100
apikey:eb5ca11fa8e46315c2df1b8e283149049e8d235e
spotid:70996

300x100
apikey:25eb32adddc4f7311c3ec7b28eac3b72bbca5656
spotid:70998

300x250
apikey:88d88a288fdea5c01d17ea8e494168e834860fd6
spotid:70356

728x90
apikey:2e0b9e0b3f40d952e6000f1a8c4d455fffc4ca3a
spotid:70999

アイコン
apikey:2349edefe7c2742dfb9f434de23bc3c7ca55ad22
spotid:101281

nendの×64対応について

marble seijin の開発日記 admobでもxcode5にはまる

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8