- Home /
The question is answered, right answer was accepted
iOS app does not play audio from bluetooth headset
Builded Unity app for iOS and Android. In iOS app audio won't be played in bluetooth headset. In android does. Headset itself works perfectly. Same problem with different bluetooth headsets.
Couldn't find any solution. Have anyone had this problem? Any glue why?
Unity 2018.1.5f1 iOS 10 and 11
Answer by martsamma · Jun 25, 2018 at 10:34 AM
Managed to FIX this problem.
Open the generated project in Xcode. Find and open UnityAppController.mm
file.
And add these lines to UnityAppController.mm
:
At the beginning of the file add:
#import <AVFoundation/AVFoundation.h>
Then find this function in mentioned file:- (void)startUnity:(UIApplication*)application
:
If you don't need to record add in the end of this function these 2 lines:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
If you need to record add in the end of this function these 2 lines:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
Please specify, that you need to add the [[AVAudioSession sharedInstance] setActive:YES error:nil]; part at the end of the same function, right now it sounds like you need to add it to the end of the file, which does not make it work.
At least i and some other developers thought of that i think.
So what exactly you need to do is:
Add #import <AVFoundation/AVFoundation.h>
at the beginning of UnityAppController.mm
file (use search inside xcode)
Then add either [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
or [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
at the end of the - (void)startUnity:(UIApplication*)application
function (search startUnity)
depending on if you require audio recording or not and also add [[AVAudioSession sharedInstance] setActive:YES error:nil];
at the end of the SA$$anonymous$$E function
@Dioinecail Thank you! Updated solution comment. Hope that it's more understandable now.