通用設定

GADMobileAds 類別提供用於控制特定特性的全域設定 由 Mobile Ads SDK 收集的資訊

影片廣告音量控制項

如果您的應用程式有專屬的音量控制項,例如自訂音樂或音效 ,只要向 Google Mobile Ads SDK 揭露應用程式音量,即可啟用影片廣告 即可遵守應用程式音量設定這樣一來,使用者就可以透過 預期音訊音量。

透過音量按鈕或 OS 層級音量滑桿控制的裝置音量, 會決定裝置音訊輸出的音量。不過,應用程式可以獨立 調整裝置音量以調整音訊 無須專人管理

針對應用程式開啟頁面廣告、橫幅廣告、插頁式廣告、獎勵廣告和插頁式獎勵廣告 可以透過下列方式向 Google Mobile Ads SDK 回報相對應用程式數量 設定 applicationVolume 屬性。有效廣告數量值的範圍介於 0.0 (靜音) 到 1.0 (目前裝置音量)。以下範例說明如何 向 SDK 回報相對應用程式數量:

Swift

func viewDidLoad() {
  super.viewDidLoad()
  // Set app volume to be half of the current device volume.
  GADMobileAds.sharedInstance().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;
  ...
}

針對應用程式開啟頁面廣告、橫幅廣告、插頁式廣告、獎勵廣告和插頁式獎勵廣告 時,只要通知 Google Mobile Ads SDK,應用程式 設定 applicationMuted 屬性以忽略:

Swift

GADMobileAds.sharedInstance().applicationMuted = true

Objective-C

GADMobileAds.sharedInstance.applicationMuted = YES;

applicationVolume 的預設設定是 1 (目前的裝置音量) applicationMuted 設為 NO

原生廣告

詳情請見 GADVideoOptions敬上 瞭解如何控制靜音設定。原生廣告沒有 支援自訂音量控制

音訊工作階段

您可以透過音訊工作階段向系統表達您對應用程式的意圖 音訊行為如要進一步瞭解音訊工作階段,請前往 Apple 的音訊工作階段程式設計 指南。 管理 Google Mobile Ads SDK 音訊的方法有很多種 這個 audioVideoManager敬上 資源。

如果您未在應用程式中使用音訊,就不需要這些 API。Google Mobile Ads SDK 自動管理音訊工作階段類別 播放音訊。假使您經常使用應用程式播放音訊,而且希望更嚴格的 Google Mobile Ads SDK 播放音訊的方式和時機,您不妨使用這些 API。

在音訊影片管理員中,您可以 audioSessionIsApplicationManaged敬上 如果您想要負責管理音訊,則屬性設為 YES 工作階段類別

如要管理音訊工作階段類別,可以加入 GADAudioVideoManagerDelegate敬上 並設定 delegate 即可接收廣告影片和音訊通知 播放事件。然後,請將音訊工作階段類別變更為 相關類別 (依據 Apple 的 Audio Session 策劃) 指南

以下提供簡化的程式碼範例,方便您瞭解: 應用程式會使用上述 API 播放音樂:

Swift

func setUp() {
  GADMobileAds.sharedInstance().audioVideoManager.delegate = self
  GADMobileAds.sharedInstance().audioVideoManager.audioSessionIsApplicationManaged = false
}

// MARK: - GADAudioVideoManagerDelegate
func audioVideoManagerWillPlayAudio(_ audioVideoManager: GADAudioVideoManager) {
  // The 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()
}

func audioVideoManagerDidStopPlayingAudio(_ audioVideoManager: GADAudioVideoManager) {
  // The 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()
}

Objective-C

- (void)setUp {
  GADMobileAds.sharedInstance.audioVideoManager.delegate = self;
  GADMobileAds.sharedInstance.audioVideoManager.audioSessionIsApplicationManaged = NO;
}

#pragma mark - GADAudioVideoManagerDelegate

- (void)audioVideoManagerWillPlayAudio:(GADAudioVideoManager *)audioVideoManager {
  // The 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 {
    // The 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 相關的例外狀況 才能錄製,您可以呼叫 disableSDKCrashReporting 方法。呼叫此方法的最佳時機為 應用程式啟動後:

Swift

import GoogleMobileAds

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(_ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    GADMobileAds.disableSDKCrashReporting()
    return true
  }
}

Objective-C

@import GoogleMobileAds;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  [GADMobileAds disableSDKCrashReporting];
  return YES;
}

@end

如果您的應用程式有特殊需求,您可以設定選用 NSUserDefaults敬上 gad_has_consent_for_cookies。Google Mobile Ads SDK 支援 受限制的廣告 表示 gad_has_consent_for_cookies 偏好設定設為零。

Swift

UserDefaults.standard.set(0, forKey: "gad_has_consent_for_cookies")

Objective-C

NSUserDefaults.standardUserDefaults().setObject(Int(0),
    forKey: "gad_has_consent_for_cookies");