How to find out if an external headset is connected to an iPhone?Play audio if headset is plugged-inDetecting iPhone/iPod Touch AccessoriesWhat kind of routes could I get back from kAudioSessionProperty_AudioRoute property?Iphone How to know if Bluetooth headset connectedDo we have a builtin Bluetooth connection listener in iOS?How can I develop for iPhone using a Windows development machine?Iphone How to know if Bluetooth headset connectediPhone 3.5mm jack based applicationHow to get list of paired Bluetooth headsets on iPhone?Use built-in mic if Headset is plugged inHow to tell when your iPhone audio is being rerouted to an external device?Redirect audio output to hdmi connector(iPhone) -How to use built-in mic if Headset is plugged in?Two-channel recording on the iPhone/iPad: headset + built-in micRecording from Built-In Mic when Playing through Bluetooth in iOS
How did researchers find articles before the Internet and the computer era?
Who voices the character "Finger" in The Fifth Element?
Does any Greek word have a geminate consonant after a long vowel?
Why do changes to /etc/hosts take effect immediately?
Is it okay to fade a human face just to create some space to place important content over it?
Should fiction mention song names and iPods?
Prime parity peregrination
In native German words, is Q always followed by U, as in English?
Why is Japan trying to have a better relationship with Iran?
How is this practical and very old scene shot?
Movie in a trailer park named Paradise and a boy playing a video game then being recruited by aliens to fight in space
Lifting a probability measure to the power set
Chords behaving as a melody
Meaning of じゃないんじゃない?
How can my story take place on Earth without referring to our existing cities and countries?
How hard is it to sell a home which is currently mortgaged?
Is the location of an aircraft spoiler really that vital?
Could a Weapon of Mass Destruction, targeting only humans, be developed?
What exactly did Ant-Man see that made him say that their plan worked?
Was it really unprofessional of me to leave without asking for a raise first?
Why transcripts instead of degree certificates?
Why would anyone even use a Portkey?
Choosing my first bike
How do I tell the reader that my character is autistic in Fantasy?
How to find out if an external headset is connected to an iPhone?
Play audio if headset is plugged-inDetecting iPhone/iPod Touch AccessoriesWhat kind of routes could I get back from kAudioSessionProperty_AudioRoute property?Iphone How to know if Bluetooth headset connectedDo we have a builtin Bluetooth connection listener in iOS?How can I develop for iPhone using a Windows development machine?Iphone How to know if Bluetooth headset connectediPhone 3.5mm jack based applicationHow to get list of paired Bluetooth headsets on iPhone?Use built-in mic if Headset is plugged inHow to tell when your iPhone audio is being rerouted to an external device?Redirect audio output to hdmi connector(iPhone) -How to use built-in mic if Headset is plugged in?Two-channel recording on the iPhone/iPad: headset + built-in micRecording from Built-In Mic when Playing through Bluetooth in iOS
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Is it possible to detect that the user has an external headset plugged into the iPhone's 3.5mm connector or the 30-pin connector? I want to output audio only to an external audio device, and keep silent if nothing is connected.
iphone objective-c core-audio
add a comment |
Is it possible to detect that the user has an external headset plugged into the iPhone's 3.5mm connector or the 30-pin connector? I want to output audio only to an external audio device, and keep silent if nothing is connected.
iphone objective-c core-audio
add a comment |
Is it possible to detect that the user has an external headset plugged into the iPhone's 3.5mm connector or the 30-pin connector? I want to output audio only to an external audio device, and keep silent if nothing is connected.
iphone objective-c core-audio
Is it possible to detect that the user has an external headset plugged into the iPhone's 3.5mm connector or the 30-pin connector? I want to output audio only to an external audio device, and keep silent if nothing is connected.
iphone objective-c core-audio
iphone objective-c core-audio
edited Aug 15 '17 at 17:16
Cœur
21.1k10 gold badges120 silver badges167 bronze badges
21.1k10 gold badges120 silver badges167 bronze badges
asked Mar 25 '10 at 23:57
iteriter
2,0916 gold badges28 silver badges49 bronze badges
2,0916 gold badges28 silver badges49 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The answer is very similar to the answer to this question, but you'll want to get the kAudioSessionProperty_AudioRoute property instead.
Thanks! This is what I need. Now I wonder what are the possible values for the Auidio_Route property.
– iter
Mar 26 '10 at 0:36
For possible values, see this discussion: stackoverflow.com/questions/2753562/…
– Reuven
Jul 7 '11 at 21:48
add a comment |
Call this method to find out the bluetooth headset is connected or not.
First import this framework #import <AVFoundation/AVFoundation.h>
- (BOOL) isBluetoothHeadsetConnected
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription *routeDescription = [session currentRoute];
NSLog(@"Current Routes : %@", routeDescription);
if (routeDescription)
NSArray *outputs = [routeDescription outputs];
if (outputs && [outputs count] > 0)
AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0];
NSString *portType = [portDescription portType];
NSLog(@"dataSourceName : %@", portType);
if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"])
return YES;
return NO;
add a comment |
There is nice article about this in Apple documentation:
https://developer.apple.com/documentation/avfoundation/avaudiosession/responding_to_audio_session_route_changes
Only you have to verify if portType == AVAudioSessionPortBluetoothA2DP
func setupNotifications()
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self,
selector: #selector(handleRouteChange),
name: .AVAudioSessionRouteChange,
object: nil)
@objc func handleRouteChange(notification: Notification)
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue:reasonValue) else
return
switch reason
case .newDeviceAvailable:
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = true
break
case .oldDeviceUnavailable:
if let previousRoute =
userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription
for output in previousRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = false
break
default: ()
func isBluetoothHeadsetConnected() -> Bool
var result = false
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
result = true
return result
2
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Answers that are little more than a link may be deleted
– adiga
Mar 25 at 11:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2520296%2fhow-to-find-out-if-an-external-headset-is-connected-to-an-iphone%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The answer is very similar to the answer to this question, but you'll want to get the kAudioSessionProperty_AudioRoute property instead.
Thanks! This is what I need. Now I wonder what are the possible values for the Auidio_Route property.
– iter
Mar 26 '10 at 0:36
For possible values, see this discussion: stackoverflow.com/questions/2753562/…
– Reuven
Jul 7 '11 at 21:48
add a comment |
The answer is very similar to the answer to this question, but you'll want to get the kAudioSessionProperty_AudioRoute property instead.
Thanks! This is what I need. Now I wonder what are the possible values for the Auidio_Route property.
– iter
Mar 26 '10 at 0:36
For possible values, see this discussion: stackoverflow.com/questions/2753562/…
– Reuven
Jul 7 '11 at 21:48
add a comment |
The answer is very similar to the answer to this question, but you'll want to get the kAudioSessionProperty_AudioRoute property instead.
The answer is very similar to the answer to this question, but you'll want to get the kAudioSessionProperty_AudioRoute property instead.
edited May 23 '17 at 11:53
Community♦
11 silver badge
11 silver badge
answered Mar 26 '10 at 0:05
ChuckChuck
206k29 gold badges273 silver badges371 bronze badges
206k29 gold badges273 silver badges371 bronze badges
Thanks! This is what I need. Now I wonder what are the possible values for the Auidio_Route property.
– iter
Mar 26 '10 at 0:36
For possible values, see this discussion: stackoverflow.com/questions/2753562/…
– Reuven
Jul 7 '11 at 21:48
add a comment |
Thanks! This is what I need. Now I wonder what are the possible values for the Auidio_Route property.
– iter
Mar 26 '10 at 0:36
For possible values, see this discussion: stackoverflow.com/questions/2753562/…
– Reuven
Jul 7 '11 at 21:48
Thanks! This is what I need. Now I wonder what are the possible values for the Auidio_Route property.
– iter
Mar 26 '10 at 0:36
Thanks! This is what I need. Now I wonder what are the possible values for the Auidio_Route property.
– iter
Mar 26 '10 at 0:36
For possible values, see this discussion: stackoverflow.com/questions/2753562/…
– Reuven
Jul 7 '11 at 21:48
For possible values, see this discussion: stackoverflow.com/questions/2753562/…
– Reuven
Jul 7 '11 at 21:48
add a comment |
Call this method to find out the bluetooth headset is connected or not.
First import this framework #import <AVFoundation/AVFoundation.h>
- (BOOL) isBluetoothHeadsetConnected
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription *routeDescription = [session currentRoute];
NSLog(@"Current Routes : %@", routeDescription);
if (routeDescription)
NSArray *outputs = [routeDescription outputs];
if (outputs && [outputs count] > 0)
AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0];
NSString *portType = [portDescription portType];
NSLog(@"dataSourceName : %@", portType);
if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"])
return YES;
return NO;
add a comment |
Call this method to find out the bluetooth headset is connected or not.
First import this framework #import <AVFoundation/AVFoundation.h>
- (BOOL) isBluetoothHeadsetConnected
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription *routeDescription = [session currentRoute];
NSLog(@"Current Routes : %@", routeDescription);
if (routeDescription)
NSArray *outputs = [routeDescription outputs];
if (outputs && [outputs count] > 0)
AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0];
NSString *portType = [portDescription portType];
NSLog(@"dataSourceName : %@", portType);
if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"])
return YES;
return NO;
add a comment |
Call this method to find out the bluetooth headset is connected or not.
First import this framework #import <AVFoundation/AVFoundation.h>
- (BOOL) isBluetoothHeadsetConnected
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription *routeDescription = [session currentRoute];
NSLog(@"Current Routes : %@", routeDescription);
if (routeDescription)
NSArray *outputs = [routeDescription outputs];
if (outputs && [outputs count] > 0)
AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0];
NSString *portType = [portDescription portType];
NSLog(@"dataSourceName : %@", portType);
if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"])
return YES;
return NO;
Call this method to find out the bluetooth headset is connected or not.
First import this framework #import <AVFoundation/AVFoundation.h>
- (BOOL) isBluetoothHeadsetConnected
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription *routeDescription = [session currentRoute];
NSLog(@"Current Routes : %@", routeDescription);
if (routeDescription)
NSArray *outputs = [routeDescription outputs];
if (outputs && [outputs count] > 0)
AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0];
NSString *portType = [portDescription portType];
NSLog(@"dataSourceName : %@", portType);
if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"])
return YES;
return NO;
answered Dec 8 '16 at 5:26
pradip sutariyapradip sutariya
1379 bronze badges
1379 bronze badges
add a comment |
add a comment |
There is nice article about this in Apple documentation:
https://developer.apple.com/documentation/avfoundation/avaudiosession/responding_to_audio_session_route_changes
Only you have to verify if portType == AVAudioSessionPortBluetoothA2DP
func setupNotifications()
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self,
selector: #selector(handleRouteChange),
name: .AVAudioSessionRouteChange,
object: nil)
@objc func handleRouteChange(notification: Notification)
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue:reasonValue) else
return
switch reason
case .newDeviceAvailable:
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = true
break
case .oldDeviceUnavailable:
if let previousRoute =
userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription
for output in previousRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = false
break
default: ()
func isBluetoothHeadsetConnected() -> Bool
var result = false
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
result = true
return result
2
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Answers that are little more than a link may be deleted
– adiga
Mar 25 at 11:59
add a comment |
There is nice article about this in Apple documentation:
https://developer.apple.com/documentation/avfoundation/avaudiosession/responding_to_audio_session_route_changes
Only you have to verify if portType == AVAudioSessionPortBluetoothA2DP
func setupNotifications()
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self,
selector: #selector(handleRouteChange),
name: .AVAudioSessionRouteChange,
object: nil)
@objc func handleRouteChange(notification: Notification)
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue:reasonValue) else
return
switch reason
case .newDeviceAvailable:
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = true
break
case .oldDeviceUnavailable:
if let previousRoute =
userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription
for output in previousRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = false
break
default: ()
func isBluetoothHeadsetConnected() -> Bool
var result = false
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
result = true
return result
2
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Answers that are little more than a link may be deleted
– adiga
Mar 25 at 11:59
add a comment |
There is nice article about this in Apple documentation:
https://developer.apple.com/documentation/avfoundation/avaudiosession/responding_to_audio_session_route_changes
Only you have to verify if portType == AVAudioSessionPortBluetoothA2DP
func setupNotifications()
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self,
selector: #selector(handleRouteChange),
name: .AVAudioSessionRouteChange,
object: nil)
@objc func handleRouteChange(notification: Notification)
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue:reasonValue) else
return
switch reason
case .newDeviceAvailable:
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = true
break
case .oldDeviceUnavailable:
if let previousRoute =
userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription
for output in previousRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = false
break
default: ()
func isBluetoothHeadsetConnected() -> Bool
var result = false
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
result = true
return result
There is nice article about this in Apple documentation:
https://developer.apple.com/documentation/avfoundation/avaudiosession/responding_to_audio_session_route_changes
Only you have to verify if portType == AVAudioSessionPortBluetoothA2DP
func setupNotifications()
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self,
selector: #selector(handleRouteChange),
name: .AVAudioSessionRouteChange,
object: nil)
@objc func handleRouteChange(notification: Notification)
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue:reasonValue) else
return
switch reason
case .newDeviceAvailable:
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = true
break
case .oldDeviceUnavailable:
if let previousRoute =
userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription
for output in previousRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
headsetConnected = false
break
default: ()
func isBluetoothHeadsetConnected() -> Bool
var result = false
let session = AVAudioSession.sharedInstance()
for output in session.currentRoute.outputs where output.portType == AVAudioSessionPortBluetoothA2DP
result = true
return result
edited Mar 25 at 13:26
answered Mar 25 at 11:50
Petro NovosadPetro Novosad
493 bronze badges
493 bronze badges
2
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Answers that are little more than a link may be deleted
– adiga
Mar 25 at 11:59
add a comment |
2
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Answers that are little more than a link may be deleted
– adiga
Mar 25 at 11:59
2
2
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Answers that are little more than a link may be deleted
– adiga
Mar 25 at 11:59
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Answers that are little more than a link may be deleted
– adiga
Mar 25 at 11:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2520296%2fhow-to-find-out-if-an-external-headset-is-connected-to-an-iphone%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown