Last active
January 17, 2017 20:12
-
-
Save jwerle/07c271eb65ecbaed322a52dfd27fe69c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface SilentSwitchOverrider : NSObject | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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