<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreHaptics",
  "identifier" : "/documentation/CoreHaptics/CHHapticEngine/init(audioSession:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Haptics"
    ],
    "preciseIdentifier" : "c:objc(cs)CHHapticEngine(im)initWithAudioSession:error:"
  },
  "title" : "init(audioSession:)"
}
-->

# init(audioSession:)

Creates a haptic engine from an audio session.

```
init(audioSession: AVAudioSession?) throws
```

## Parameters

`audioSession`

The shared audio session, if you’re already using one in your app, to sync with the created engine. For example, pass in <doc://com.apple.documentation/documentation/AVFAudio/AVAudioSession/sharedInstance()> if you’re using audio from <doc://com.apple.documentation/documentation/AVFAudio/AVAudioSession>. Pass in `nil` to use default <doc://com.apple.documentation/documentation/UIKit> audio behavior.

## Discussion

Create your haptic engine with this initializer if you want the audio behavior of your engine to match other audio APIs in your app. For example, if you’re using <doc://com.apple.documentation/documentation/AVFAudio/AVAudioSession> to manage audio elsewhere in your app, then you want to share the session’s <doc://com.apple.documentation/documentation/AVFAudio/AVAudioSession/sharedInstance()>. In this case, the engine mutes and routes audio in accordance with the passed session.

Otherwise, if you don’t pass it a session, it won’t behave the same way as elsewhere in app; audio behaves like <doc://com.apple.documentation/documentation/UIKit>, without syncing to a specific session. You should pass `nil` when you need the engine only for playing haptics.

---

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)