<br />

The `GADMobileAds` class provides global settings for controlling certain
information collected by Google Mobile Ads SDK.

## Video ad volume control

> [!NOTE]
> **Note:** Video volume controls apply only to Google ads and are not forwarded to mediation networks.

If your app has its own volume controls, such as custom music or sound effect
volumes, disclosing app volume to Google Mobile Ads SDK enables video ads
to respect app volume settings. This ensures users receive video ads with the
expected audio volume.

The device volume, controlled through volume buttons or OS-level volume slider,
determines the volume for device audio output. However, apps can independently
adjust volume levels relative to the device volume to tailor the audio
experience.

For App Open, Banner, Interstitial, Rewarded, and Rewarded Interstitial ad
formats you can report the relative app volume to Google Mobile Ads SDK by
setting the `applicationVolume` property. Valid ad volume values range from
`0.0` (silent) to `1.0` (current device volume). Here's an example of how to
report the relative app volume to the SDK:

### Swift

```swift
func viewDidLoad() {
  super.viewDidLoad()
  // Set app volume to be half of the current device volume.
  MobileAds.shared.applicationVolume = 0.5
  ...
}
```

### Objective-C

```objective-c
- (void)viewDidLoad {
  [super viewDidLoad];
  // Set app volume to be half of the current device volume.
  GADMobileAds.sharedInstance.applicationVolume = 0.5;
  ...
}
```

> [!WARNING]
> **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.

For App Open, Banner, Interstitial, Rewarded, and Rewarded Interstitial ad
formats, you can inform Google Mobile Ads SDK that the app volume has been
muted by setting the `applicationMuted` property:

### Swift

```swift
MobileAds.shared.applicationMuted = true
```

### Objective-C

```objective-c
GADMobileAds.sharedInstance.applicationMuted = YES;
```

By default, `applicationVolume` is set to `1` (the current device volume)
and `applicationMuted` is set to `NO`.

> [!WARNING]
> **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.

### Native ads

See
[`GADVideoOptions`](https://developers.google.com/admob/ios/native/options.md.txt#gadvideooptions)
for instructions on controlling the mute settings. For native ads, there isn't
support for custom volume control.

## Audio sessions

Audio sessions let you express to the system your intentions for your app's
audio behavior. Additional information on audio sessions can be found in
Apple's [Audio Session Programming
Guide](https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html).
The available options for managing Google Mobile Ads SDK audio is through
the
[`audioVideoManager`](https://developers.google.com/admob/ios/api/reference/Classes/GADMobileAds.md.txt#audioVideoManager)
property.

If you don't use audio in your app, you don't need to use these APIs.
Google Mobile Ads SDK automatically manages the audio session category when it
plays audio. If you do play audio in your app and you want tighter control of
how and when Google Mobile Ads SDK plays audio, you can make use of these APIs.

On the audio video manager, you can set the
[`audioSessionIsApplicationManaged`](https://developers.google.com/admob/ios/api/reference/Classes/GADAudioVideoManager.md.txt#audioSessionIsApplicationManaged)
property to `YES` if you want to take responsibility for managing the audio
session category yourself.

If you want to manage the audio session category, you can implement
[`GADAudioVideoManagerDelegate`](https://developers.google.com/admob/ios/api/reference/Protocols/GADAudioVideoManagerDelegate.md.txt)
and set the [`delegate`](https://developers.google.com/admob/ios/api/reference/Classes/GADAudioVideoManager.md.txt#/c:objc(cs)GADAudioVideoManager(py)delegate)
property on the audio video manager to be notified of ads video and audio
playback events. You should then change the audio session category to the
relevant category according to [Apple's Audio Session Programming
Guide](https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html).

> [!IMPORTANT]
> **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`](https://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`.

Here is a simplified code sample that shows the recommended approach if your
app plays music, using the above APIs:

### Swift

```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

```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];
}
```

## Crash reporting

Google Mobile Ads SDK inspects exceptions that occur in an iOS app and
records them if they were caused by the SDK. These exceptions are then
addressed in future SDK versions.

Crash reporting is enabled by default. If you don't want SDK-related exceptions
to be recorded, you can disable this feature by calling the
`disableSDKCrashReporting` method. The best time to call this method is when
the app launches:

### Swift

```swift
import GoogleMobileAds

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

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

    MobileAds.shared.disableSDKCrashReporting()
    return true
  }
}
```

### Objective-C

```objective-c
@import GoogleMobileAds;

@implementation AppDelegate

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

  \[GADMobileAds disableSDKCrashReporting\];
  return YES;
}

@end
```

## Consent for cookies settings

If your app has special requirements, you can set the optional
[`NSUserDefaults`](https://developer.apple.com/documentation/foundation/nsuserdefaults)
`gad_has_consent_for_cookies`. Google Mobile Ads SDK enables

[limited ads (LTD)](https://support.google.com/admob/answer/10105530)

if the `gad_has_consent_for_cookies` preference is set to zero.

### Swift

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

### Objective-C

```objective-c
NSUserDefaults.standardUserDefaults().setObject(Int(0),
    forKey: "gad_has_consent_for_cookies");
```