フルスクリーン広告の導入 - united-adstir/AdStir-Integration-Guide-iOS GitHub Wiki
SDKの更新
SDKを更新する際はパッケージに含まれる全てのSDKを更新してください。 バージョンの異なるSDKをご利用の場合、正常に動作しない可能性があります。
こちらの変更履歴をご覧になってから導入を開始してください。
必要条件
XCode 9以上 iOS 8.0以上
adstir SDK 2.12.0よりiOS 8.0以上の端末にのみ配信されます。
対応提携ネットワークについて
対応提携ネットワークについてはこちらのページをご覧ください。
初期設定
初期設定をご覧になり、adstir SDKをプロジェクトへ導入してください。
対応提携ネットワークを導入する場合はこちらを参考に対応提携ネットワークを導入してください。
広告の設置
- 動画広告の初期化を行う
- フルスクリーン広告のインスタンスを生成
- デリゲートの実装(オプション)
- フルスクリーン広告の読み込み
- フルスクリーン広告の再生
1. 動画広告の初期化を行う
AdstirVideoAds prepareWithMedia
を使い、プロジェクトで利用する全ての動画広告の初期化を同時に行います。動画リワード広告とフルスクリーン広告を併用する場合は、同時に初期化を行う必要があります。
[AdstirVideoAds prepareWithMedia:@"メディアID" spots:@[@枠No1, @枠No2]];
2. フルスクリーン広告のインスタンスを生成
AdstirInterstitial
のインスタンスを生成します。
AdstirInterstitial *interstitial = [[AdstirInterstitial alloc] initWithMedia:@"メディアID" spot:枠No];
3. デリゲートの実装(オプション)
- (void)viewDidLoad {
[super viewDidLoad];
:
interstitial.delegate = self;
:
}
/** インタースティシャル広告の準備が完了した際に呼び出されます */
- (void)adstirInterstitialDidLoad:(AdstirInterstitial * __asadnonnull)interstitial
{
}
/** インタースティシャル広告の準備に失敗した際に呼び出されます */
- (void)adstirInterstitial:(AdstirInterstitial * __asadnonnull)interstitial didFailToLoadWithError:(NSError * __asadnonnull)error
{
}
/** インタースティシャル広告が表示された際に呼び出されます */
- (void)adstirInterstitialDidShow:(AdstirInterstitial * __asadnonnull)interstitial
{
}
/** インタースティシャル広告の表示に失敗した際に呼び出されます */
- (void)adstirInterstitial:(AdstirInterstitial * __asadnonnull)interstitial didFailToShowWithError:(NSError * __asadnonnull)error
{
}
/** インタースティシャル広告が閉じられたときに呼び出されます */
- (void)adstirInterstitialDidClose:(AdstirInterstitial * __asadnonnull)interstitial
{
}
4. フルスクリーン広告の読み込み
フルスクリーン広告の読み込みを行います。
[interstitial load];
5. フルスクリーン広告の再生
読み込みが完了したフルスクリーン広告を再生します。
動画の再生を行うViewControllerを渡してください。
動画の再生後、もう一度動画を再生するためには4.フルスクリーン広告の読み込み
を行う必要があります。
if (self.interstitial.canShow) {
[self.interstitial showFromViewController:self];
}
SDKの実装例
ここでは、単純な実装についてのサンプルを提示します。
まず、Storyboard上に、UIButton
とUILabel
を配置し、UIButton
をのOutletとActionをshowInterstitialButton
とshowInterstitialButtonDidTouchUpInside
にそれぞれ接続し、UILabel
のOutletをstatusLabel
に接続してください。
SDKの実装
Swift
- AppDelegate.swift
// ...
import AdstirAds
// ...
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
/* 他の初期化コード */
// メディアIDと、このアプリ内で利用するイン対すティシャル広告のメディアIDと、枠Noをすべて指定します。
AdstirVideoAds.prepare(withMedia:"メディアID", spots: [枠No, 枠No])
return true
}
// ...
}
- ViewController.swift
import UIKit
import AdstirAds
class ViewController: UIViewController, AdstirInterstitialDelegate {
@IBOutlet weak var showInterstitialButton: UIButton!
@IBOutlet weak var statusLabel: UILabel!
var interstitial: AdstirInterstitial?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.showInterstitialButton.enabled = false
// メディアIDと、このアプリ内で利用する動画インセンティブメニューの枠IDとインタースティシャル広告の枠IDをすべて指定します。
// 動画リワードとインタースティシャルを併用する場合はどちらの枠Noも指定してください。
let interstitial = AdstirInterstitial.init(media: "メディアID", spot: 枠No)
interstitial?.delegate = self;
self.interstitial = interstitial
self.statusLabel.text = "Loading...";
interstitial?.load()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func showInterstitialButtonDidTouchUpInside(sender: AnyObject) {
self.showInterstitialButton.enabled = false
if (self.interstitial != nil && self.interstitial!.canShow()) {
self.interstitial?.showFromViewController(self)
}
}
/**
Called when get ready to show ad
インタースティシャル広告の準備が完了した際に呼び出されます
*/
func adstirInterstitialDidLoad(interstitial: AdstirInterstitial) {
NSLog("広告の読み込みが完了しました")
self.statusLabel.text = "Loaded"
self.showInterstitialButton.enabled = true
}
/**
Called when failed to load ad
インタースティシャル広告の準備に失敗した際に呼び出されます
*/
func adstirInterstitial(interstitial: AdstirInterstitial, didFailToLoadWithError error: NSError) {
NSLog("広告の読み込みに失敗しました")
// 15秒待ってから再読み込みします
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(15.0 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
self.statusLabel.text = "Loading...";
self.interstitial?.load()
})
}
/**
Called when interstitial ad is shown
インタースティシャル広告が表示された際に呼び出されます
*/
func adstirInterstitialDidShow(interstitial: AdstirInterstitial) {
NSLog("広告が表示されました")
self.statusLabel.text = ""
}
/**
Called when failed to show ad
インタースティシャル広告の表示に失敗した際に呼び出されます
*/
func adstirInterstitial(interstitial: AdstirInterstitial, didFailToShowWithError error: NSError) {
NSLog("広告の表示に失敗しました")
// 15秒待ってから再読み込みします
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(15.0 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
self.statusLabel.text = "Loading...";
self.interstitial?.load()
})
}
/**
Called when ad was closed
インタースティシャル広告が閉じられたときに呼び出されます
*/
func adstirInterstitialDidClose(interstitial: AdstirInterstitial) {
NSLog("広告が閉じられました")
// 15秒待ってから再読み込みします
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(15.0 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
self.statusLabel.text = "Loading...";
self.interstitial?.load()
})
}
deinit {
self.interstitial?.delegate = nil
self.interstitial = nil
}
}
Objective-C
- AppDelegate.m
// ...
@import AdstirAds;
// ...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* 他の初期化コード */
// メディアIDと、このアプリ内で利用する動画インセンティブメニューの枠IDとインタースティシャル広告の枠IDをすべて指定します。
// 動画リワードとインタースティシャルを併用する場合はどちらの枠Noも指定してください。
[AdstirVideoAds prepareWithMedia:@"メディアID" spots:@[@枠No]];
return YES;
}
- ViewController.m
// ...
@import AdstirAds;
// ...
@interface ViewController () <AdstirInterstitialDelegate>
@property (weak, nonatomic) IBOutlet UIButton *showInterstitialButton;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (strong, nonatomic) AdstirInterstitial *interstitial;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
AdstirInterstitial *interstitial = [[AdstirInterstitial alloc] initWithMedia:@"メディアID" spot:枠No];
interstitial.delegate = self;
self.interstitial = interstitial;
self.statusLabel.text = @"Loading...";
[interstitial load];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/** フルスクリーン広告を表示するボタンのターゲットメソッド */
- (IBAction)showInterstitialButtonDidTouchUpInside:(id)sender {
self.showInterstitialButton.enabled = NO;
if (self.interstitial.canShow) {
[self.interstitial showFromViewController:self];
}
}
/**
Called when get ready to show ad
インタースティシャル広告の準備が完了した際に呼び出されます
*/
- (void)adstirInterstitialDidLoad:(AdstirInterstitial * __asadnonnull)interstitial
{
NSLog(@"広告の読み込みが完了しました");
self.statusLabel.text = @"Loaded";
self.showInterstitialButton.enabled = YES;
}
/**
Called when failed to load ad
インタースティシャル広告の準備に失敗した際に呼び出されます
*/
- (void)adstirInterstitial:(AdstirInterstitial * __asadnonnull)interstitial didFailToLoadWithError:(NSError * __asadnonnull)error
{
NSLog(@"広告の読み込みに失敗しました");
// 15秒待ってから再読み込みします
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Loading...";
[self.interstitial load];
});
}
/**
Called when interstitial ad is shown
インタースティシャル広告が表示された際に呼び出されます
*/
- (void)adstirInterstitialDidShow:(AdstirInterstitial * __asadnonnull)interstitial
{
NSLog(@"広告が表示されました");
self.statusLabel.text = @"";
}
/**
Called when failed to show ad
インタースティシャル広告の表示に失敗した際に呼び出されます
*/
- (void)adstirInterstitial:(AdstirInterstitial * __asadnonnull)interstitial didFailToShowWithError:(NSError * __asadnonnull)error
{
NSLog(@"広告の表示に失敗しました");
// 15秒待ってから再読み込みします
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Loading...";
[self.interstitial load];
});
}
/**
Called when ad was closed
インタースティシャル広告が閉じられたときに呼び出されます
*/
- (void)adstirInterstitialDidClose:(AdstirInterstitial * __asadnonnull)interstitial
{
NSLog(@"広告が閉じられました");
// 15秒待ってから再読み込みします
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Loading...";
[self.interstitial load];
});
}
- (void)dealloc
{
// デリゲートを解放します。解放を忘れるとクラッシュする可能性があります。
self.interstitial.delegate = nil;
// 広告の制御インスタンスを解放します。
self.interstitial = nil;
}
@end
ライブラリ詳細
APIリファレンスをご覧ください。
よくある質問
レポートに表示回数が反映されません
開発版とリリース版のパッケージ名が異なる場合、一部の提携ネットワークで実績の取得が行われないことがございます。 その際は、リリース版と同じパッケージ名に変更いただいた上でテストいただくか、開発版とリリース版のパッケージ名が異なる旨を添えていただき、レポート数値について営業担当にお問い合わせください。
「You may not prepare AdstirInterastitial.」と表示される
初期化処理が行われていません。
AdstirInterstitial.prepare(withMedia:, spots:)
もしくは+ [AdstirInterstitial prepareWithMedia:spots]
を利用して必ず初期化を実施してください。
更新履歴
変更履歴をご覧ください。