<!--
{
  "availability" : [
    "iOS: 4.0.0 - 6.0.0",
    "iPadOS: 4.0.0 - 6.0.0",
    "macCatalyst: 14.0.0 - 14.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioSession/setActive(_:withFlags:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioSession(im)setActive:withFlags:error:"
  },
  "title" : "setActive(_:withFlags:)"
}
-->

# setActive(_:withFlags:)

Activates or deactivates your app’s audio session; provides flags for use by other audio sessions.

```
func setActive(_ active: Bool, withFlags flags: Int) throws
```

## Parameters

`active`

Use <doc://com.apple.documentation/documentation/Swift/true> to activate your app’s audio session or <doc://com.apple.documentation/documentation/Swift/false> to deactivate it.

`flags`

A bitmapped value containing one or more flags.

## Discussion

If another app’s active audio session has higher priority than your app, and that other audio session doesn’t allow mixing with other apps, attempting to activate your audio session might fail.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)