My app is a Bluetooth companion app for a MFi certified headset. I'm trying to implement a feature to start recording the audio from the mic on the headset when user presses a button on the headset. I'm using External Accessory Framework to receive the record command from headset, and then using AudioToolbox to start the recording. It works fine if the recording starts when the app is in the foreground. However, it does not record anything when the app is in the background. Here's the code snippet that sets up the audio session before recording:
Here's the error code I received:
I couldn't find any related entitlement from https://developer.apple.com/documentation/bundleresources/entitlements?language=objc.
Has anyone have the same issue? Any workaround?
Code Block objc NSError *error; AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVoiceChat options:AVAudioSessionCategoryOptionAllowBluetooth|AVAudioSessionCategoryOptionMixWithOthers error:&error]; NSError *activationError = nil; BOOL isActivated = [audioSession setActive:YES error:&activationError]; NSString *isActivatedString = isActivated ? @"True" : @"False"; for (AVAudioSessionPortDescription *desc in [audioSession availableInputs]){ if (desc.portType == AVAudioSessionPortBluetoothHFP) { NSError *error; BOOL didSet = [audioSession setPreferredInput:desc error:&error]; } }
Here's the error code I received:
Code Block -CMSUtilities- CMSUtility_IsAllowedToStartRecording: Client sid:0x25c53, <private>(2556), 'prim' with PID 2556 is in the background and doesn't have the entitlement to start recording in the background.
I couldn't find any related entitlement from https://developer.apple.com/documentation/bundleresources/entitlements?language=objc.
Has anyone have the same issue? Any workaround?