-
Notifications
You must be signed in to change notification settings - Fork 0
COMPASS SDK for iOS Apps
-
対象 OS
iOS 8.0 以上 -
最新の Xcode を使用
-
利用フレームワーク
- UIKit.framework
- AdSupport.framework
- CoreLocation.framework (位置情報サービスを利用する場合)
- GoogleMobileAds.Framework (AdMob Mediation を利用する場合)
-
サードパーティーライブラリ管理
- CocoaPods (GoogleMobleAds を導入するため)
ダウンロードしたファイルを解凍し, COMPASS SDK と COMPASS SDK が利用しているライブラリーを導入する.
-
導入後,
Configurations画面で利用しているビルドスキームをコピーする. -
コピーしたスキームを
Productionにリネームする. -
ビルド設定画面 (プロダクトメニュー →
Scheme→Edit Scheme) を開いてRunとArchiveのBuild Configuration項目ではProductionスキームを設定する. -
Info.plist に COMPASS プロパティを読み込むため下記ような設定を追加する.
<key>CompassConfiguration</key> <string>${CONFIGURATION}</string>

- Info.plist に追加するプロパティは以下を参照.
| キー | 型 | 値 |
|---|---|---|
| CompassSDKInlineSpotID | String | 管理画面にて発行されたインライン広告枠コード インライン広告を使用する場合に設定 |
| CompassSDKInterstitialSpotID | String | 管理画面にて発行されたインタースティシャル広告枠コード インタースティシャル広告を使用する場合に設定 |
| CompassSDKLocationEnable | Boolean | 広告表示に位置情報を利用するか 利用する場合: YES 利用しない場合: NO (デフォルト) |
| CompassSDKInlineRotation | Boolean | 広告のローテーションを行うか 行う場合: YES 行わない場合: NO (デフォルト) |
| NSLocationWhenInUseUsageDescription | String | 位置情報取得の許可を求めるためのメッセージ 位置情報を連携させる場合は必須 |
| NSLocationAlwaysUsageDescription | String | 位置情報取得の許可を求めるためのメッセージ 位置情報を連携させる場合は必須 |
例:
<key>CompassSDKInlineRotation</key>
<false/>
<key>CompassSDKInlineSpotID</key>
<string></string>
<key>CompassSDKInterstitialSpotID</key>
<string></string>
<key>CompassSDKLocationEnabled</key>
<false/>
<key>NSLocationAlwaysUsageDescription</key>
<string>Location Always?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location WhenInUse?</string>CompassView を実装するクラスのヘッダファイルに CompassView をインポートする.
#import "CompassView.h"CompassView のプロトコルメソッドを実装する場合, ヘッダファイルにあるインターフェースで宣言する.
@interface ViewController : UIViewController <CompassViewDelegate>CompassView を実装するクラスのインターフェースの中に CompassView を宣言する.
@property (nonatomic, retain) CompassView *compassView;
// Storyboard で UIView のインスタンス生成する
@property (weak, nonatomic) IBOutlet UIView *inlineUIView;CompassView を実装するインプレメンテーションクラスの中に CompassView のインスタンスを生成して必要なプロパティを定義する.
self.compassView = [[CompassView alloc] initWithUIView:self.inlineUIView];
// プロトコルメソッドを使う時, デリゲートをアサインする.
[self.compassView setDelegate:self];
// ビューの番号を設定する
[self.compassView setTag:1];
// 位置情報サービスへのリクエスト
[self.compassView requestLocation:YES];
// 広告をロードする
[self.compassView load];- メソッド一覧
| メソッド名 | 引数 | 引数概要 | 戻り値 | 概要 |
|---|---|---|---|---|
| initWithUIView | (UIView *)view | 広告を表示するview | id | 広告を表示する View を指定して初期化 |
| load | - | - | void | 広告の読み込み Info.plist に 設定している広告を表示する |
| load | (NSString *)spotID | 表示したい広告のspotID | void | 広告の読み込み 引数で指定した広告を表示させる |
| deallocAdvertisement | - | - | void | 広告の割り当てを解除する |
| reload | - | - | void | 広告の再読み込み Info.plist に 設定している広告を表示する |
| reload | (NSString *)spotID | 表示したい広告のspotID | void | 広告の再読み込み 引数で指定した広告を表示させる |
| requestLocation | (BOOL)shouldRequestLocationRepeatedly | 常に位置情報を取得するか YES :行う NO:行わない |
void | 位置情報の許可ダイアログを表示 広告でのみ位置情報を取得させる場合に呼び出しが必要 |
- プロトコルメソッド (任意)
| メソッド名 | 引数 | 引数概要 | 概要 |
|---|---|---|---|
| isLoadCompassSuccess | (NSInteger)tag | ビューのタグ | 広告のロード成功 |
| isShowCompass | (NSInteger)tag | ビューのタグ | 広告の表示完了 |
| isLoadCompassFailure | (NSInteger)tag (NSError *)error |
ビューのタグ エラー情報 |
広告のロード失敗 エラーの内訳は下表を参照 |
- エラー情報概要
| NSError 変数名・キー名 | 概要 |
|---|---|
| Domain | エラードメイン CVErrorDomain で固定 |
| Code | エラーコード 各概要については下表を参照 |
| UserInfo | エラー情報詳細 |
| NSLocalizedDescription | エラー概要 (英語) |
| NSLocalizedRecoverySuggestion | 復旧方法 (英語) |
| CVSuperError | ラップした元の NSError クラス |
- エラーコード概要
| エラーコード | 概要 |
|---|---|
| CVErrorCodeFailureHttp | HTTP 通信によるエラー 数秒後にリトライを行う |
| CVErrorCodeFailureHttpNoRetry | HTTP 通信によるエラー リトライは行わない |
| CVErrorCodeFailureRtb | RTB 失敗によるエラー |
| CVErrorCodeInvalidDisplayType | 表示種別不正によるエラー |
| CVErrorCodeFailureLocation | 位置情報取得失敗によるエラー |
| CVErrorCodeErrorSystem | システムエラー |

CompassInterstitial を実装するクラスのヘッダファイルに CompassInterstitial をインポートする.
#import <UIKit/UIKit.h>
#import "CompassInterstitial.h"
#import "CompassInterstitialDelegate.h"CompassInterstitial のプロトコルメソッドを実装する場合, ヘッダファイルにあるインターフェースで宣言する.
@interface ViewController : UIViewController <CompassInterstitialDelegate>CompassInterstitial を実装するクラスのインターフェースの中に CompassInterstitial を宣言する.
@property (nonatomic, retain) CompassInterstitial *compassInterstitialVC;CompassInterstitial を実装するインプレメンテーションクラスの中に CompassInterstitial のインスタンスを生成して必要なプロパティを定義する.
self.compassInterstitialVC = [[CompassInterstitial alloc]initWithSpotId:NULL];
// プロトコルメソッドを使う時, デリゲートをアサインする.
[self.compassInterstitialVC setDelegate:self];
// 広告をリクエストする
[self.compassInterstitialVC requestAd];位置情報を使う場合
self.compassInterstitialVC = [[CompassInterstitial alloc]initWithSpotId:NULL];
// プロトコルメソッドを使う時, デリゲートをアサインする.
[self.compassInterstitialVC setDelegate:self];
// 広告をリクエストする
[self.compassInterstitialVC requestAdUseLocation:YES];表示する場合
[self.compassInterstitialVC presentCompassInterstitialFromParentViewController:self];CompassInterstitial のインスタンスが一回しか使えません. 広告を複数回表示する場合は didDismissCompassInterstitial というプロトコルメソッドの中で新しいインスタンスを作成してください.
-
メソッド一覧
メソッド名 引数 引数概要 戻り値 概要 initWithSpotId: spotId COMPASS 管理画面で発行されて広告 ID の文字列 CompassInterstitial SpotId を定義して初期化した CompassInterstitial のインスタンス requestAd - - - インタースティシャル広告をリクエストする requestAdUseLocation shouldRequestLocationRepeatedly 常に位置情報を取得するか
YES: 行う
NO: 行わない- 位置情報の許可ダイアログを表示
広告でのみ位置情報を取得させる場合に呼び出しが必要presentCompassInterstitialFromParentViewController: parentViewController インタースティシャルビューを表示する ViewController - インタースティシャル広告を表示する isInterstitialLoaded - - YES: ロードが完了
NO: ロードが未完了広告のロードが完了になったかどうか -
必須のプロトコルメソッド
メソッド名 引数 引数概要 概要 didDismissCompassInterstitial: compassInterstitial 閉じた CompassInterstitial のインスタンス インタースティシャル広告の非表示完了 -
任意のプロトコルメソッド
メソッド名 引数 引数概要 概要 compassInterstitialDidLoad: compassInterstitial 読み込む CompassInterstitial のインスタンス 広告のロード成功 willPresentCompassInterstitial: compassInterstitial 表示する CompassInterstitial のインスタンス 広告を表示する didPresentCompassInterstitial: compassInterstitial 表示した CompassInterstitial のインスタンス 広告の表示完了 willDismissCompassInterstitial: compassInterstitial 閉じる CompassInterstitial のインスタンス 広告を非表示する compassInterstitialWasClicked: compassInterstitial タップした CompassInterstitial のインスタンス 広告をタップした compassInterstitialDidFailToLoad:withNSError: compassInterstitial,
error読み込む CompassInterstitial のインスタンス,
エラー情報広告のロード失敗 -
エラー情報概要
| NSError 変数名・キー名 | 概要 |
|---|---|
| Domain | エラードメイン CVErrorDomain で固定 |
| Code | エラーコード 各概要については下表を参照 |
| UserInfo | エラー情報詳細 |
| NSLocalizedDescription | エラー概要 (英語) |
| NSLocalizedRecoverySuggestion | 復旧方法 (英語) |
| CVSuperError | ラップした元の NSError クラス |
- エラーコード概要
| エラーコード | 概要 |
|---|---|
| CVErrorCodeFailureHttp | HTTP 通信によるエラー 数秒後にリトライを行う |
| CVErrorCodeFailureHttpNoRetry | HTTP 通信によるエラー リトライは行わない |
| CVErrorCodeFailureRtb | RTB 失敗によるエラー |
| CVErrorCodeInvalidDisplayType | 表示種別不正によるエラー |
| CVErrorCodeFailureLocation | 位置情報取得失敗によるエラー |
| CVErrorCodeErrorSystem | システムエラー |
| CIVErrorCodeFailureShow | インタースティシャル広告表示失敗によるエラー |

事前
- COMPASS SDK をインポート
- COMPASS SDK ビルド設定
- Info.plist に COMPASS SDK の設定を追加
- CocoaPods で GoogleMobileAds SDK をインストールする
- AdMob 管理画面でアプリを登録
CocoaPods をインストールしていない場合, ターミナルで下のコマンドを実行する. (参考: CocoaPods)
$ sudo gem install cocoapods
CocoaPods のインストール完了後, GoogleMobileAds を導入する.
ターミナルで以下のコマンドを実行する.
Podfile を作成する.
$ pod init
Xcode で Podfile を開く.
$ open -a Xcode Podfile
Xcode で開いた Podfile に 以下を追加する.
pod 'Google-Mobile-Ads-SDK'
Podfile を保存して閉じる.
GoogleMobileAds を導入する.
$ pod install

AdMob Mediation を使う場合 .xcodeproj ではなく CocoaPods で生成された .xcworkspace を使う.

| 項目 | 値 |
|---|---|
| Class Name | CompassCustomEventBanner (バナー) CompassCustomEventInterstitial (インタースティシャル) |
| Label | AdMob のリポートに使うラベル (変更不可能) |
| Parameter | COMPASS 管理画面で発行された広告枠 ID |
GoogleMobileAds をインポートする.
@import GoogleMobileAds;GADBannerView のデリゲートを使うする時, 宣言する.
@interface ViewController : UIViewController <GADBannerViewDelegate> {
.
.
.
}GADBannerView を実装するクラスの中に宣言する
// StoryBoard や xib ファイルから GADBannerView のインスタンス生成
@property (weak, nonatomic) IBOutlet GADBannerView *customEventBanner;GADBannerView のインスタンスを生成し, プロパティを定義する.
GADRequest *bannerRequest = [GADRequest request];
self.customEventBanner.adUnitID = customEventBannerAdUnitID;
self.customEventBanner.adSize = kGADAdSizeBanner;
self.customEventBanner.rootViewController = self;
self.customEventBanner.delegate = self;
[self.customEventBanner loadRequest:bannerRequest];GADBannerView の詳しいことは Firebase のバナーへ
GoogleMobileAds をインポートする.
@import GoogleMobileAdsGADInterstitial のデリゲートを使うする時, 宣言する.
@interface ViewController : UIViewController <GADInterstitialDelegate> {
.
.
.
}GADInterstitial を実装するクラスの中に宣言する
// StoryBoard や xib ファイルから GADInterstitial のインスタンス生成
@property (weak, nonatomic) IBOutlet UIButton *showInterstitialButton;
@property (nonatomic, strong) GADInterstitial *customEventInterstitial;GADInterstitial のインスタンスを生成し, プロパティを定義する. GADInterstitial のインスタンスは一回しか使いないため, GADInterstitial ビューが閉じた場合に GADInterstitial のインスタンスを再度生成すること.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//GADInterstitial
[self requestGADCustomEventInterstitial];
- (IBAction)showInterstitial:(id)sender {
if (self.customEventInterstitial.isReady) {
[self.customEventInterstitial presentFromRootViewController:self];
}
}
#pragma mark GADInterstitial Delegate Methods
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
[self requestGADCustomEventInterstitial];
}
GADInterstitial の詳しいことは Firebase のインタースティシャルへ
COMPASS SDK とライブラリのインポートしビルド設定を行った後に, "Bridging header" ファイルを作成する. ("Bridging Header" ファイルが .xcodeproj または .xcworkspace の同じディレクトリに配置する.)
"Bridging header" ファイルに以下のコードを追加する
#import <UIKit/UIKit.h>
// CompassView API を使う場合
#import "CompassView.h"
// CompassInterstitial API を使う場合
#import "CompassInterstitial.h"
// CompassInterstitial プロトコルメソッドを使う場合
#import "CompassInterstitialDelegate.h"CompassView のプロトコルメソッドを実装する場合, 宣言する.
class ViewController: UIViewController, CompassViewDelegateCompassView を実装するクラスの中に CompassView を宣言する.
@IBOutlet weak var inlineView: UIView!
var inline: CompassView?CompassView を実装するメソッドの中に CompassView のインスタンスを生成して必要なプロパティを定義する.
inline = CompassView.init(uiView: inlineView)
// プロトコルメソッドを使う時, デリゲートをアサインする.
inline?.delegate = self
// 広告をロードする
inline?.load()
CompassInterstitial のプロトコルメソッドを実装する場合, 宣言する.
class ViewController: UIViewController, CompassInterstitialDelegateCompassInterstitial を実装するクラスの中に CompassInterstitial を宣言する.
var interstitial : CompassInterstitial?CompassInterstitial を実装するメソッドの中に CompassInterstitial のインスタンスを生成して必要なプロパティを定義する.
interstitial = CompassInterstitial.init(spotId: nil)
// プロトコルメソッドを実装する時, デリゲートをアサインする.
interstitial?.delegate = self
// 広告をリクエストする
interstitial?.requestAd()位置情報を使う場合
interstitial = CompassInterstitial.init(spotId: nil)
// プロトコルメソッドを実装する時, デリゲートをアサインする.
interstitial?.delegate = self
// 広告をリクエストする
interstitial?.requestAdUseLocation(true)表示する場合
interstitial?.present(fromParentViewController: self)CompassInterstitial のインスタンスが一回しか使えません. 広告を複数回表示する場合は didDismiss() というプロトコルメソッドの中で新しいインスタンスを作成してください.

事前
- COMPASS SDK をインポート
- COMPASS SDK ビルド設定
- Info.plist に COMPASS SDK の設定を追加
- CocoaPods で GoogleMobileAds SDK をインストールする
- AdMob 管理画面でアプリを登録
CocoaPods をインストールしていない場合, ターミナルで下のコマンドを実行する. (参考: CocoaPods)
$ sudo gem install cocoapods
CocoaPods のインストール完了後, GoogleMobileAds を導入する.
ターミナルで以下のコマンドを実行する.
Podfile を作成する.
$ pod init
Xcode で Podfile を開く.
$ open -a Xcode Podfile
Xcode で開いた Podfile に 以下を追加する.
pod 'Google-Mobile-Ads-SDK'
Podfile を保存して閉じる.
GoogleMobileAds を導入する.
$ pod install

AdMob Mediation を使う場合 .xcodeproj ではなく CocoaPods で生成された .xcworkspace を使う.

| 項目 | 値 |
|---|---|
| Class Name | CompassCustomEventBanner (バナー) CompassCustomEventInterstitial (インタースティシャル) |
| Label | AdMob のリポートに使うラベル(変更不可能) |
| Parameter | COMPASS 管理画面で発行された広告枠 ID |
GoogleMobileAds をインポートする
import GoogleMobileAdsGADBannerView のデリゲートを使うする時, 下記を宣言する.
class ViewController: UIViewController, GADBannerViewDelegate {
.
.
.
} GADBannerView を実装するクラスの中に宣言する.
// StoryBoard や xib ファイルからインスタンス生成
@IBOutlet weak var customEventBanner: GADBannerView!GADBannerView のインスタンスを生成し, プロパティを定義する.
self.customEventBanner.adUnitID = "ca-app-pub-6044252762240745/2111939912"
self.customEventBanner.delegate = self
self.customEventBanner.rootViewController = self
self.customEventBanner.load(GADRequest())GADBannerView の詳しいことは Firebase のバナーへ
GoogleMobileAds をインポートする.
import GoogleMobileAdsGADInterstitial のデリゲートを使う場合, 下記を宣言する.
class ViewController: UIViewController, GADInterstitialDelegate {
.
.
.
} GADInterstitial を実装するクラスの中に宣言する
// StoryBoard や xib ファイルからインスタンス生成
@IBOutlet weak var showInterstitial: UIButton!
var customEventInterstitial : GADInterstitial!GADInterstitial のインスタンスを生成し, プロパティを定義する. GADInterstitial のインスタンスは一回しか使えないため, GADInterstitial ビューを閉じた場合に GADInterstitial のインスタンスを再度生成すること.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.customEventInterstitial = loadInterstitialAd()
}
// インタースティシャルをロード
func loadInterstitialAd() -> GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "ca-app-pub-6044252762240745/3588673112")
interstitial.delegate = self
interstitial.load(GADRequest())
return interstitial
}
@IBAction func showAd(sender: AnyObject) {
if self.customEventInterstitial.isReady {
self.customEventInterstitial.present(fromRootViewController: self)
}
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
self.customEventInterstitial = loadInterstitialAd()
}GADInterstitialの詳しいことは Firebaseのインタースティシャルへ
