---
title: "init(audioSession:)"
framework: corehaptics
role: symbol
role_heading: Initializer
path: "corehaptics/chhapticengine/init(audiosession:)"
---

# init(audioSession:)

Creates a haptic engine from an audio session.

## Declaration

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

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 AVAudioSession to manage audio elsewhere in your app, then you want to share the session’s 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 UIKit, without syncing to a specific session. You should pass nil when you need the engine only for playing haptics.

## See Also

### Initializing a Haptic Engine

- [init()](corehaptics/chhapticengine/init().md)
