iOS Question Headphone detect

You can use this code to test whether headphones are plugged in:

Code:
Public Sub IsHeadsetPluggedIn As Boolean
   Dim no As NativeObject = Me
   Return no.RunMethod("isHeadsetPluggedIn", Null).AsBoolean
End Sub

#if objc
#import <AVFoundation/AVFoundation.h>
- (BOOL)isHeadsetPluggedIn {
  AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute];
  for (AVAudioSessionPortDescription* desc in [route outputs]) {
  if ([[desc portType] isEqualToString:AVAudioSessionPortHeadphones])
  return YES;
  }
  return NO;
}
#end if

Code:
Log(IsHeadsetPluggedIn)
 
Upvote 0
Back
Top