swiftavaudiosessionairplay

How do I get my app to show the "Tap to Airplay" banner on launch


I would like my app to show the airplay suggestion like Spotify does.

I have enabled background audio in the app's capabilities, I use try audioSession.setCategory(.playback) on app launch, and then I call .setActive() when audio is about to be played. But my app does not show the airplay banner - I have to enable airplay manually either in Control Center or using the AVRoutePickerView button in the app.

Does anyone know how to make this appear?

enter image description here


Solution

  • Unfortunately, it's not possible to force trigger this banner. The "Tap to Airplay" banner isn't being triggered by the Spotify app, iOS is recognizing that you are near an Airplay compatible device and that you often use Airplay within the Spotify app, which supports long form video, and then makes a decision based on this and other factors, which Apple does not disclose, whether to display the banner or not.

    To allow iOS to suggest or automatically AirPlay, the minimum code requirements are that you need to "add the AVInitialRouteSharingPolicy key to your app's Info.plist and set it to a long-form video."

    <key>AVInitialRouteSharingPolicy</key>
    <string>LongFormVideo</string>
    

    "If the user goes to play some content and the AirPlay routing system detects a nearby likely AirPlay device, then the system may prompt the user and suggest to AirPlay to this device. Or, depending on the confidence, the system might also automatically route playback to that device."

    https://developer.apple.com/videos/play/wwdc2019/501/?time=1775