Created
July 18, 2017 11:46
-
-
Save savelichalex/069a7585981412e5226f653c2cb9e222 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#import <React/RCTBridgeModule.h> | |
#import <React/RCTEventEmitter.h> | |
@interface HeadsetDetector : RCTEventEmitter <RCTBridgeModule> | |
@end |
This file contains hidden or 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 "HeadsetDetector.h" | |
@implementation HeadsetDetector | |
RCT_EXPORT_MODULE(); | |
- (NSArray<NSString *> *)supportedEvents | |
{ | |
return @[@"HeadsetStatusChange"]; | |
} | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(audioRoutingListenerCallback:) | |
name:AVAudioSessionRouteChangeNotification | |
object:nil]; | |
- (void)audioRoutingListenerCallback:(NSNotification*)notification | |
{ | |
NSDictionary *interuptionDict = notification.userInfo; | |
NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue]; | |
switch (routeChangeReason) { | |
case AVAudioSessionRouteChangeReasonNewDeviceAvailable: | |
[self sendEventWithName:@"HeadsetStatusChange" body:@{@"isPlugged": true}]; | |
break; | |
case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: | |
[self sendEventWithName:@"HeadsetStatusChange" body:@{@"isPlugged": false}]; | |
break; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment