Skip to content

Instantly share code, notes, and snippets.

@jwerle
Last active January 17, 2017 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwerle/07c271eb65ecbaed322a52dfd27fe69c to your computer and use it in GitHub Desktop.
Save jwerle/07c271eb65ecbaed322a52dfd27fe69c to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@interface SilentSwitchOverrider : NSObject
@end
#import "SilentSwitchOverrider.h"
#import <AVFoundation/AVFoundation.h>
@interface SilentSwitchOverrider() {}
@property (nonatomic) AVAudioSession* audioSession;
@property (nonatomic) NSString* prevCategory;
@property (nonatomic) NSInteger prevOptions;
@end
@implementation SilentSwitchOverrider
- (id) init {
self = [super init];
if (self) {
_audioSession = [AVAudioSession sharedInstance];
_prevCategory = [_audioSession category];
_prevOptions = [_audioSession categoryOptions];
NSError *setCategoryError = nil;
if (![_audioSession setCategory: AVAudioSessionCategoryPlayback
withOptions: AVAudioSessionCategoryOptionMixWithOthers
error: &setCategoryError]) {
// handle error
}
}
return self;
}
-(void) dealloc {
NSError *setCategoryError = nil;
if (![_audioSession setCategory: _prevCategory
withOptions: _prevOptions
error: &setCategoryError]) {
// handle error
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment