funcsetUp(){MobileAds.shared.audioVideoManager.delegate=selfMobileAds.shared.audioVideoManager.audioSessionIsApplicationManaged=false}// MARK: - GADAudioVideoManagerDelegatefuncaudioVideoManagerWillPlayAudio(_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()}funcaudioVideoManagerDidStopPlayingAudio(_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.sharedInstancepauseAllMusic];}-(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.sharedInstanceresumeAllMusic];}
崩溃报告
Google 移动广告 SDK 会检查 iOS 应用中发生的异常,并会记录 SDK 所引发的异常。然后,在未来的 SDK 版本中解决这些异常。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThe \u003ccode\u003eGADMobileAds\u003c/code\u003e class allows you to control global settings for the Mobile Ads SDK, including video ad volume and audio session management.\u003c/p\u003e\n"],["\u003cp\u003eYou can adjust app volume or mute state to influence video ad behavior, but lowering/muting volume can reduce ad eligibility and revenue.\u003c/p\u003e\n"],["\u003cp\u003eFor native ads, mute settings are controlled through \u003ccode\u003eGADVideoOptions\u003c/code\u003e, while custom volume control is not supported.\u003c/p\u003e\n"],["\u003cp\u003eIf your app plays audio, you can manage the audio session or utilize the \u003ccode\u003eGADAudioVideoManagerDelegate\u003c/code\u003e to control audio interactions between your app and ads.\u003c/p\u003e\n"],["\u003cp\u003eThe SDK includes crash reporting by default, but you can disable it if needed; you can also set consent for cookies using \u003ccode\u003eNSUserDefaults\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/global-settings \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/global-settings \"View this page for the iOS platform docs.\") [Unity](/ad-manager/mobile-ads-sdk/unity/global-settings \"View this page for the Unity platform docs.\")\n\n\u003cbr /\u003e\n\nThe `GADMobileAds` class provides global settings for controlling certain\ninformation collected by Google Mobile Ads SDK.\n\nVideo ad volume control **Note:** Video volume controls apply only to Google ads and are not forwarded to mediation networks.\n\nIf your app has its own volume controls, such as custom music or sound effect\nvolumes, disclosing app volume to Google Mobile Ads SDK enables video ads\nto respect app volume settings. This ensures users receive video ads with the\nexpected audio volume.\n\nThe device volume, controlled through volume buttons or OS-level volume slider,\ndetermines the volume for device audio output. However, apps can independently\nadjust volume levels relative to the device volume to tailor the audio\nexperience.\n\nFor App Open, Banner, Interstitial, Rewarded, and Rewarded Interstitial ad\nformats you can report the relative app volume to Google Mobile Ads SDK by\nsetting the `applicationVolume` property. Valid ad volume values range from\n`0.0` (silent) to `1.0` (current device volume). Here's an example of how to\nreport the relative app volume to the SDK: \n\nSwift \n\n func viewDidLoad() {\n super.viewDidLoad()\n // Set app volume to be half of the current device volume.\n MobileAds.shared.applicationVolume = 0.5\n ...\n }\n\nObjective-C \n\n - (void)viewDidLoad {\n [super viewDidLoad];\n // Set app volume to be half of the current device volume.\n GADMobileAds.sharedInstance.applicationVolume = 0.5;\n ...\n }\n\n| **Warning:** Lowering your app's audio volume reduces video ad eligibility and might reduce your app's ad revenue. You should only utilize this API if your app provides custom volume controls to the user, and the user's volume is properly reflected in the API.\n\nFor App Open, Banner, Interstitial, Rewarded, and Rewarded Interstitial ad\nformats, you can inform Google Mobile Ads SDK that the app volume has been\nmuted by setting the `applicationMuted` property: \n\nSwift \n\n MobileAds.shared.applicationMuted = true\n\nObjective-C \n\n GADMobileAds.sharedInstance.applicationMuted = YES;\n\nBy default, `applicationVolume` is set to `1` (the current device volume)\nand `applicationMuted` is set to `NO`.\n| **Warning:** Muting your app reduces video ad eligibility and might reduce your app's ad revenue. You should only utilize this API if your app provides a custom mute control to the user, and the user's mute decision is properly reflected in the API.\n\nNative ads\n\nSee\n[`GADVideoOptions`](/ad-manager/mobile-ads-sdk/ios/native/options#gadvideooptions)\nfor instructions on controlling the mute settings. For native ads, there isn't\nsupport for custom volume control.\n\nAudio sessions\n\nAudio sessions let you express to the system your intentions for your app's\naudio behavior. Additional information on audio sessions can be found in\nApple's [Audio Session Programming\nGuide](//developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html).\nThe available options for managing Google Mobile Ads SDK audio is through\nthe\n[`audioVideoManager`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADMobileAds#audioVideoManager)\nproperty.\n\nIf you don't use audio in your app, you don't need to use these APIs.\nGoogle Mobile Ads SDK automatically manages the audio session category when it\nplays audio. If you do play audio in your app and you want tighter control of\nhow and when Google Mobile Ads SDK plays audio, you can make use of these APIs.\n\nOn the audio video manager, you can set the\n[`audioSessionIsApplicationManaged`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADAudioVideoManager#audioSessionIsApplicationManaged)\nproperty to `YES` if you want to take responsibility for managing the audio\nsession category yourself.\n\nIf you want to manage the audio session category, you can implement\n[`GADAudioVideoManagerDelegate`](/ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADAudioVideoManagerDelegate)\nand set the [`delegate`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GADAudioVideoManager#/c:objc(cs)GADAudioVideoManager(py)delegate)\nproperty on the audio video manager to be notified of ads video and audio\nplayback events. You should then change the audio session category to the\nrelevant category according to [Apple's Audio Session Programming\nGuide](//developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html).\n| **Key Point:** By default, the SDK sets the audio session category to `AVAudioSessionCategoryAmbient` when playing ads muted. If you prefer to have your app use [`AVAudioSessionCategoryOptionDuckOthers`](//developer.apple.com/documentation/avfoundation/avaudiosessioncategoryoptions/avaudiosessioncategoryoptionduckothers) in this scenario, you must implement the `GADAudioVideoManagerDelegate` protocol and set the audio video manager `audioSessionIsApplicationManaged` to `YES`.\n\nHere is a simplified code sample that shows the recommended approach if your\napp plays music, using the above APIs: \n\nSwift \n\n func setUp() {\n MobileAds.shared.audioVideoManager.delegate = self\n MobileAds.shared.audioVideoManager.audioSessionIsApplicationManaged = false\n }\n\n // MARK: - GADAudioVideoManagerDelegate\n func audioVideoManagerWillPlayAudio(_ audioVideoManager: GADAudioVideoManager) {\n // The Google Mobile Ads SDK is notifying your app that it will play audio. You\n // could optionally pause music depending on your apps design.\n MyAppObject.shared.pauseAllMusic()\n }\n\n func audioVideoManagerDidStopPlayingAudio(_ audioVideoManager: GADAudioVideoManager) {\n // The Google Mobile Ads SDK is notifying your app that it has stopped playing\n // audio. Depending on your design, you could resume music here.\n MyAppObject.shared.resumeAllMusic()\n }\n\nObjective-C \n\n - (void)setUp {\n GADMobileAds.sharedInstance.audioVideoManager.delegate = self;\n GADMobileAds.sharedInstance.audioVideoManager.audioSessionIsApplicationManaged = NO;\n }\n\n #pragma mark - GADAudioVideoManagerDelegate\n\n - (void)audioVideoManagerWillPlayAudio:(GADAudioVideoManager *)audioVideoManager {\n // Google Mobile Ads SDK is notifying your app that it will play audio. You\n // could optionally pause music depending on your apps design.\n [MyAppObject.sharedInstance pauseAllMusic];\n }\n\n - (void)audioVideoManagerDidStopPlayingAudio:(GADAudioVideoManager *)audioVideoManager {\n // Google Mobile Ads SDK is notifying your app that it has stopped playing\n // audio. Depending on your design, you could resume music here.\n [MyAppObject.sharedInstance resumeAllMusic];\n }\n\nCrash reporting\n\nGoogle Mobile Ads SDK inspects exceptions that occur in an iOS app and\nrecords them if they were caused by the SDK. These exceptions are then\naddressed in future SDK versions.\n\nCrash reporting is enabled by default. If you don't want SDK-related exceptions\nto be recorded, you can disable this feature by calling the\n`disableSDKCrashReporting` method. The best time to call this method is when\nthe app launches: \n\nSwift \n\n import GoogleMobileAds\n\n @UIApplicationMain\n class AppDelegate: UIResponder, UIApplicationDelegate {\n\n func application(_ application: UIApplication,\n didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n\n MobileAds.shared.disableSDKCrashReporting()\n return true\n }\n }\n\nObjective-C \n\n @import GoogleMobileAds;\n\n @implementation AppDelegate\n\n - (BOOL)application:(UIApplication *)application\n didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n\n \\[GADMobileAds disableSDKCrashReporting\\];\n return YES;\n }\n\n @end\n\nConsent for cookies settings\n\nIf your app has special requirements, you can set the optional\n[`NSUserDefaults`](//developer.apple.com/documentation/foundation/nsuserdefaults)\n`gad_has_consent_for_cookies`. Google Mobile Ads SDK enables\n\n[limited ads (LTD)](//support.google.com/admanager/answer/9882911)\n\nif the `gad_has_consent_for_cookies` preference is set to zero. \n\nSwift \n\n UserDefaults.standard.set(0, forKey: \"gad_has_consent_for_cookies\")\n\nObjective-C \n\n NSUserDefaults.standardUserDefaults().setObject(Int(0),\n forKey: \"gad_has_consent_for_cookies\");"]]