Integrate Apple Music playback, catalog search, and Now Playing metadata using MusicKit and MediaPlayer. Use when adding music search, Apple Music subscription flows, queue management, playback controls, remote command handling, or Now Playing info to iOS apps.
Integrate Apple Music into an iOS app — catalog search, playback, subscription checks, and Now Playing metadata — using the MusicKit and MediaPlayer frameworks, targeting Swift 6.3 and iOS 26+. It applies when adding music search, Apple Music subscription flows, queue management, playback controls, remote command handling, or Lock Screen and Control Center metadata.
Setup covers enabling the MusicKit App Service for the app's bundle ID so developer tokens are generated automatically, adding NSAppleMusicUsageDescription to Info.plist, and declaring the audio background mode for background playback. Access begins with authorization through MusicAuthorization.request(), with currentStatus available to read the setting without prompting. Catalog search uses MusicCatalogSearchRequest with a term and result types, and the guidance is explicit that playback of subscription catalog content must still be gated on MusicSubscription.current.canPlayCatalogContent — checked directly, observed via subscriptionUpdates, and paired with the musicSubscriptionOffer sheet (guarded by canBecomeSubscriber) to prompt non-subscribers.
Playback runs through ApplicationMusicPlayer.shared, which plays Apple Music content independently of the system Music app and exposes an observable state with playbackStatus. Queue management builds and mutates ApplicationMusicPlayer.Queue — assigning songs or albums, appending at the tail, or inserting after the current entry to play next. For custom (non-MusicKit) audio the document shows populating MPNowPlayingInfoCenter with title, artist, duration, elapsed time, playback rate, and artwork so the Lock Screen, Control Center, and CarPlay display track info, noting that ApplicationMusicPlayer handles this automatically for Apple Music content. Finally it registers MPRemoteCommandCenter handlers for play, pause, next, and previous — responding to Lock Screen, AirPods, and CarPlay controls — and disables unsupported commands. Common mistakes and a review checklist round out the material.
Enable the MusicKit App Service for the app's bundle ID, add NSAppleMusicUsageDescription to Info.plist, and add the audio background mode for background playback.
Read MusicSubscription.current.canPlayCatalogContent (or observe subscriptionUpdates); subscription catalog playback must be gated on this, and the musicSubscriptionOffer sheet can prompt non-subscribers.
ApplicationMusicPlayer.shared, which plays Apple Music content independently of the system Music app and exposes an observable state with playbackStatus.
Through ApplicationMusicPlayer.Queue — assign songs or albums, append items at the tail, or insert a song after the current entry to play it next.
For custom, non-MusicKit audio you populate MPNowPlayingInfoCenter yourself; ApplicationMusicPlayer handles Now Playing automatically for Apple Music content.
Quick Setup:
.claude/skills/Repository
dpearson2699/swift-ios-skills