Monday, June 29, 2026
HomeiOS Developmentios - MPRemoteCommandCenter does not reply to instructions from bluetooth machine

ios – MPRemoteCommandCenter does not reply to instructions from bluetooth machine

[ad_1]

My ios app makes use of AVQueuePlayer to play audio.

The play/pause controls work correctly from Management Heart and from ios lock display screen, however not for instructions invoked from bluetooth machine. E.g., the callbacks in my app are by no means invoked when double-tapping airpods or different third-party bluetooth headphones.

I am working on an iphone 8 plus machine with iOS 15.

I am utilizing https://developer.apple.com/documentation/avfoundation/media_playback_and_selection/creating_a_basic_video_player_ios_and_tvos/controlling_background_audio.

On app startup, it units up the audio session like this:

        let audioSession = AVAudioSession.sharedInstance()
        do {
            strive audioSession.setCategory(.playAndRecord,
                                         mode: .spokenAudio,
                                         choices: [
                                            .allowBluetooth,
                                            .defaultToSpeaker
                                         ])
            strive audioSession.setActive(true)

The app listens for play/pause occasions like this.

        let commandCenter = MPRemoteCommandCenter.shared()
        commandCenter.playCommand.addTarget { occasion in
print("play")
    return .success
        }
        commandCenter.pauseCommand.addTarget { occasion in
print("pause")
    return .success
        }
commandCenter.togglePlayPauseCommand.addTarget { occasion in
    print("toggleplaypause")
    return .success
}

Playback works appropriately by means of all bluetooth units. On lock display screen or management heart, play/pause trigger “play” and “pause” to get printed. However nothing is printed when tapping airpods. (Tapping airpods works tremendous in another audio app.)

Any concepts what is likely to be lacking?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments