<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioSession/setActive:error:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioSession(im)setActive:error:"
  },
  "title" : "setActive:error:"
}
-->

# setActive:error:

Activates or deactivates your app’s audio session.

```
- (BOOL) setActive:(BOOL) active error:(NSError **) outError;
```

## 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.

`outError`

On input, a pointer to an error object. If an error occurs, the framework sets the pointer to an <doc://com.apple.documentation/documentation/Foundation/NSError> object that describes the error. If you don’t want error information, pass in `nil`.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the system successfully changed the active state; otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Your app may activate a session with category [`playback`](/documentation/AVFAudio/AVAudioSession/Category-swift.struct/playback) when another app is hosting a call, for example to start a `SharePlay` activity. However, your app isn’t permitted to capture the microphone of the active call.

> Note:
> If you attempt to activate a session with category ``doc://com.apple.avfaudio/documentation/AVFAudio/AVAudioSession/Category-swift.struct/record`` or ``doc://com.apple.avfaudio/documentation/AVFAudio/AVAudioSession/Category-swift.struct/playAndRecord`` when another app is already hosting a call, then your session fails with the error <doc://com.apple.documentation/documentation/CoreAudioTypes/AVAudioSessionErrorInsufficientPriority>.

The session fails to activate if another audio session has higher priority than yours (such as a phone call) and neither audio session allows mixing. Deactivating an audio session with running audio objects stops the objects, makes the session inactive, and returns an <doc://com.apple.documentation/documentation/CoreAudioTypes/AVAudioSession/ErrorCode/isBusy> error.

When your app deactivates a session, the return value is <doc://com.apple.documentation/documentation/Foundation/NSExpression/false> but the active state changes to deactivate.

---

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)