πŸ“΄ SoundModeManager πŸ“³ Detect silent / ring mode on iOS device

Related tags

Audio swift ios ring silent
Overview

πŸ“΄ SoundModeManager πŸ“³

Detect silent / ring mode on the device.

Languages Platforms CocoaPods Build

Preview

πŸš€ Installation

CocoaPods

For usage and installation instructions, visit their website. To integrate AirKit into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SoundModeManager'

πŸ’» Usage

Sound mode manager doesn't work on simulators!

Create a new instance of manager:

import SoundModeManager

// Fully customized instance.
let manager = SoundModeManager(soundUrl: customSoundUrl, soundUpdatingInterval: 5)

// With custom sound file only.
let manager = SoundModeManager(soundUrl: customSoundUrl)

// With default silent sound and custom updating interval. 
let manager = SoundModeManager(soundUpdatingInterval: 5)

// Default manager configuration. 
let manager = SoundModeManager()

Update current mode once (not recommended):

import SoundModeManager

let manager = SoundModeManager()

// Mode is not determined by default.
manager.currentMode // SoundMode.notDetermined
        
// Update current mode and receive callback.
manager.updateCurrentMode { mode in
    // Mode is `.silent` or `.ring`
    manager.currentMode == mode // true
}

Observe current mode changes:

import SoundModeManager

let manager = SoundModeManager()

// Mode is not determined by default.
manager.currentMode // SoundMode.notDetermined

// Save token to manage observer and subscribe to receive changes.
let observationToken = sut.observeCurrentMode { mode in
    // Block will be called only when new mode is not the same as previous.  
    // Mode is `.silent` or `.ring`.
    manager.currentMode == mode // true
}

// Start observing current mode.
manager.beginUpdatingCurrentMode()

// End observing current mode. This method suspend all notification, but all observers are still valid.
manager.endUpdatingCurrentMode()

Invalidate observation token:

// Invalidate observation token is working the same as `NSKeyValueObservation`;
// So you are able to invalidate it manually if you need;
// Token will be invalidated automatically when it is deinited.  
observationToken.invalidate()

πŸ“œ License

Released under the MIT license. See LICENSE for details.

You might also like...
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

AudioKit AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit Synth One: Open-Source iOS Synthesizer App
AudioKit Synth One: Open-Source iOS Synthesizer App

AudioKit Synth One We've open-sourced the code for this synthesizer so that everyone is able to make changes to the code, introduce new features, fix

Classical music front-end for Apple Music: iOS app

concertino_ios Concertino is a classical music front-end for Apple Music. It's splitted in several projects. This one provides only the iOS app. (Ther

iOS application for finding formants in spoken sounds
iOS application for finding formants in spoken sounds

FORMANT PLOTTER Buy on the App Store: https://itunes.apple.com/us/app/formant-analyzer/id799183655?mt=8&uo=4&at=11l6hc&ct=fnd This is an iOS project t

:musical_keyboard: A simple iOS synthesiser powered by Pure Data. Based on the Korg Monotron Delay.

Monotone Delay A simple iOS Synthesizer based on Pure Data. You can see a short demo of the app on youtube. If you want to buy the app you can find it

Music Player for iOS which looks & feels like classic player
Music Player for iOS which looks & feels like classic player

Prodigal Music Player APP looks and feels like a classic device. Bring back the good old player to life. Screenshots Home Page Album Gallery Home Page

Voice Memos is an audio recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Swift.
Voice Memos is an audio recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Swift.

VoiceMemos Voice Memos is a voice recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Sw

Learn to Code While Building Apps - The Complete iOS Development Bootcamp
Learn to Code While Building Apps - The Complete iOS Development Bootcamp

Xylophone Our Goal The goal of this tutorial is to dive into a simple iOS recipe - how to play sound and use an Apple library called AVFoundation. The

iOS music player app that downloads music from the internet, even YouTube
iOS music player app that downloads music from the internet, even YouTube

About YouTag is an iOS music player app that downloads music from the internet, even YouTube, and manages it in a local library. Music videos can also

Releases(1.0.1)
Owner
Yurii Lysytsia
iOS Software Engineer (Swift, Objective-C)
Yurii Lysytsia
Detect-a-Beacon - An educational application using Apple iBeacon technology to detect beacons

Detect-a-Beacon An educational application using Apple iBeacon technology to det

NIKOLAY NIKITIN 1 Aug 9, 2022
Control the listening mode on your AirPods Pro in the Touch Bar or Menu Bar.

NoiseBuddy Change noise cancelling settings on your AirPods Pro or Beats Solo Pro directly from your Mac's Menu Bar or Touch Bar. I wanted an easier w

Guilherme Rambo 692 Dec 27, 2022
This is a mysic detection app that uses ShazamKit to detect music. O

This is a mysic detection app that uses ShazamKit to detect music. Once it detects the music, it takes the information about that music to find lyrics for that song using a Lyrics API.

Shubham Arya 6 Dec 20, 2022
Extensions and classes in Swift that make it easy to get an iOS device reading and processing MIDI data

MorkAndMIDI A really thin Swift layer on top of CoreMIDI that opens a virtual MIDI destination and port and connects to any MIDI endpoints that appear

Brad Howes 11 Nov 5, 2022
This app demonstrates how to use the Google Cloud Speech API and Apple on-device Speech library to recognize speech in live recorded audio.

SpeechRecognitionIOS This app demonstrates how to use Google Cloud Speech API and Apple on-device Speech library to recognize speech in live audio rec

Josh Uvi 0 Mar 11, 2022
Background sounds feature from iOS 15 on iOS 11+

Tranquil Background sounds feature from iOS 15 on iOS 11+ Only physically tested on iOS 14.3 and iOS 12.1.2, but it should support iOS 11 - iOS 15.x (

Dana Buehre 4 Dec 15, 2022
AudiosPlugin is a Godot iOS Audio Plugin that resolves the audio recording issue in iOS for Godot Engine.

This plugin solves the Godot game engine audio recording and playback issue in iOS devices. Please open the Audios Plugin XCode Project and compile the project. You can also use the libaudios_plugin.a binary in your project.

null 3 Dec 22, 2022
AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 9.5k Dec 31, 2022
AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

AudioPlayer AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

Tom Baranes 260 Nov 27, 2022
Soundable is a tiny library that uses AVFoundation to manage the playing of sounds in iOS applications in a simple and easy way

Soundable is a tiny library that uses AVFoundation to manage the playing of sounds in iOS applications in a simple and easy way. You can play

Luis CΓ‘rdenas 89 Nov 21, 2022