GADMobileAds クラスは、Google Mobile Ads SDK によって収集される特定の情報を制御するためのグローバル設定を提供します。
動画広告の音量調整
アプリに独自の音量調整機能(音楽や効果音のカスタム音量設定など)が備わっている場合、アプリの音量設定を Google Mobile Ads SDK に開示すれば、動画広告の音量にもアプリ側の音量設定を反映できます。これにより、動画広告をユーザーの想定どおりの音量で視聴してもらうことが可能になります。
デバイスの音声出力の大きさは、デバイスのボリューム(ボリューム ボタンや OS レベルのボリューム スライダーで制御)で決まりますが、アプリでは音声の聞こえ方を独自にコントロールするために、デバイスの設定に対する相対的なボリューム レベルを独自に調節できます。
アプリ起動、バナー、インタースティシャル、リワード、リワード インタースティシャルの各広告フォーマットでは、applicationVolume プロパティを設定することで、アプリの相対音量を Google Mobile Ads SDK にレポートできます。広告の音量設定値の有効範囲は、0.0(無音)から 1.0(デバイスの現在の音量)までです。アプリ側の相対音量設定を SDK に伝えるコードは、たとえば次のようになります。
Swift
func viewDidLoad() {
super.viewDidLoad()
// Set app volume to be half of the current device volume.
MobileAds.shared.applicationVolume = 0.5
...
}
Objective-C
- (void)viewDidLoad {
[super viewDidLoad];
// Set app volume to be half of the current device volume.
GADMobileAds.sharedInstance.applicationVolume = 0.5;
...
}
アプリ起動、バナー、インタースティシャル、リワード、リワード インタースティシャルの各広告フォーマットでは、applicationMuted プロパティを設定することで、アプリの音量がミュートされていることを Google Mobile Ads SDK に通知できます。
Swift
MobileAds.shared.applicationMuted = true
Objective-C
GADMobileAds.sharedInstance.applicationMuted = YES;
デフォルトでは、applicationVolume は 1(デバイスの現在の音量)に設定され、applicationMuted は NO に設定されます。
ネイティブ広告
ミュート設定を制御する手順については、GADVideoOptions をご覧ください。ネイティブ広告では、カスタム音量調節機能はサポートされていません。
オーディオ セッション
オーディオ セッションでは、アプリの音声動作について、ご自身の意図をシステムに表明できます。オーディオ セッションについて詳しくは、Apple の Audio Session Programming Guide をご覧ください。Google Mobile Ads SDK 音声を管理するためのオプションは、audioVideoManager プロパティを通じて利用できます。
アプリで音声を使用しない場合は、これらの API を使用する必要はありません。Google Mobile Ads SDK は、音声を再生するときにオーディオ セッションのカテゴリを自動的に管理します。アプリで音声を再生し、Google Mobile Ads SDK が音声を再生する方法とタイミングをより厳密に制御したい場合は、これらの API を使用できます。
オーディオ動画マネージャーで、オーディオ セッション カテゴリの管理を自分で行う場合は、audioSessionIsApplicationManaged プロパティを YES に設定できます。
オーディオ セッション カテゴリを管理する場合は、GADAudioVideoManagerDelegate を実装し、オーディオ動画マネージャーで delegate プロパティを設定して、広告動画と音声の再生イベントの通知を受け取ることができます。次に、Apple のオーディオ セッション プログラミング ガイドに沿って、オーディオ セッション カテゴリを関連するカテゴリに変更する必要があります。
以下は、アプリが音楽を再生する場合に上記の API を使用して推奨されるアプローチを示す簡略化されたコードサンプルです。
Swift
func setUp() {
MobileAds.shared.audioVideoManager.delegate = self
MobileAds.shared.audioVideoManager.audioSessionIsApplicationManaged = false
}
// MARK: - GADAudioVideoManagerDelegate
func audioVideoManagerWillPlayAudio(_ audioVideoManager: GADAudioVideoManager) {
// The Google Mobile Ads SDK is notifying your app that it will play audio. You
// could optionally pause music depending on your apps design.
MyAppObject.shared.pauseAllMusic()
}
func audioVideoManagerDidStopPlayingAudio(_ audioVideoManager: GADAudioVideoManager) {
// The Google Mobile Ads SDK is notifying your app that it has stopped playing
// audio. Depending on your design, you could resume music here.
MyAppObject.shared.resumeAllMusic()
}
Objective-C
- (void)setUp {
GADMobileAds.sharedInstance.audioVideoManager.delegate = self;
GADMobileAds.sharedInstance.audioVideoManager.audioSessionIsApplicationManaged = NO;
}
#pragma mark - GADAudioVideoManagerDelegate
- (void)audioVideoManagerWillPlayAudio:(GADAudioVideoManager *)audioVideoManager {
// Google Mobile Ads SDK is notifying your app that it will play audio. You
// could optionally pause music depending on your apps design.
[MyAppObject.sharedInstance pauseAllMusic];
}
- (void)audioVideoManagerDidStopPlayingAudio:(GADAudioVideoManager *)audioVideoManager {
// Google Mobile Ads SDK is notifying your app that it has stopped playing
// audio. Depending on your design, you could resume music here.
[MyAppObject.sharedInstance resumeAllMusic];
}
クラッシュ レポート
Google Mobile Ads SDK は、iOS アプリで発生した例外を検査し、SDK が原因で発生した場合は記録します。これらの例外は、今後の SDK バージョンで対応されます。
クラッシュ レポートはデフォルトで有効になっています。SDK 関連の例外を記録したくない場合は、disableSDKCrashReporting メソッドを呼び出してこの機能を無効にできます。このメソッドを呼び出す最適なタイミングは、アプリの起動時です。
Swift
import GoogleMobileAds
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
MobileAds.shared.disableSDKCrashReporting()
return true
}
}
Objective-C
@import GoogleMobileAds;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GADMobileAds disableSDKCrashReporting];
return YES;
}
@end
Cookie の設定に対する同意
アプリに特別な要件がある場合は、オプションの NSUserDefaults
gad_has_consent_for_cookies を設定できます。gad_has_consent_for_cookies がゼロに設定されている場合、Google Mobile Ads SDK により制限付き広告(LTD)が有効になります。
Swift
UserDefaults.standard.set(0, forKey: "gad_has_consent_for_cookies")
Objective-C
NSUserDefaults.standardUserDefaults().setObject(Int(0),
forKey: "gad_has_consent_for_cookies");