musickit
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.
By dpearson2699 · 2,682 installs
npx skills add dpearson2699/swift-ios-skills --skill musickit
Source repository · Upstream listing
MusicKit
Search the Apple Music catalog, manage playback with ApplicationMusicPlayer ,
check subscriptions, and publish Now Playing metadata via MPNowPlayingInfoCenter
and MPRemoteCommandCenter .
Contents
[Setup]( setup)
[Workflow]( workflow)
[Authorization]( authorization)
[Catalog Search]( catalog search)
[Subscription Checks]( subscription checks)
[Playback with ApplicationMusicPlayer]( playback with applicationmusicplayer)
[Queue Management]( queue management)
[Now Playing Info]( now playing info)
[Remote Command Center]( remote command center)
[Common Mistakes]( common mistakes)
[Review Checklist]( review checklist)
[References]( references)
Workflow
1. Verify the MusicKit App Service, bundle identifier, purpose string, and background audio mode before debugging code.
2. Request authorization, then model every non authorized state explicitly.
3. Search or load catalog content and check MusicSubscription.current before queueing playback.
4. Choose ApplicationMusicPlayer for app scoped playback; wire Now Playing and remote commands only when the app owns those surfaces.
5. Test authorized, denied, unsubscribed, offline, queue failure, interruption, and track change states. Fix the smallest failing layer, restore the fixture, and rerun the same state matrix.
Setup
Project Configuration
1. Enable the MusicKit App Service for the app's explicit bundle ID in the Apple Developer portal so MusicKit can generate developer tokens automatically.
2. Add NSAppleMusicUsageDescription to Info.plist explaining why the app accesses the user's media library.
3. For background playback, add the audio background mode to UIBackgroundModes .
Imports
Authorization
Request permission before accessing the user's music data or playing Apple Music
content. request() presents Apple's consent dialog when necessary; use
currentStatus to read the current setting without prompting.
Catalog Search
Use MusicCatalogSearchRequest to search the Apple Music catalog. Catalog lookup
can fetch Apple Music resources, but playback of subscription catalog content
must still be gated on MusicSubscription.current.canPlayCatalogContent .
Displaying Results
Subscription Checks
Check whether the user has an active Apple Music subscription before offering playback features.
Offering Apple Music
Present the Apple Music subscription offer sheet when the user is not subscribed.
Check canBecomeSubscriber first, and pass MusicSubscriptionOffer.Options or
onLoadCompletion when the sheet needs contextual metadata or load error handling.
Playback with ApplicationMusicPlayer
ApplicationMusicPlayer plays Apple Music content independently from the Music app. It does not affect the system player's state.
Observing Playback State
Queue Management
Build and manipulate the playback queue using ApplicationMusicPlayer.Queue .
Now Playing Info
Update MPNowPlayingInfoCenter so the Lock Screen, Control Center, and CarPlay
display current track metadata. This is essential when playing custom audio
(non MusicKit sources). ApplicationMusicPlayer handles this automatically for
Apple Music content.
Adding Artwork
Remote Command Center
Register handlers for MPRemoteCommandCenter to respond to Lock Screen controls,
AirPods tap gestures, and CarPlay buttons.
Scrubbing Support
Common Mistakes
Mistake Fix
Debugging authorization before configuring the App Service and purpose string Verify service, bundle ID, and NSAppleMusicUsageDescription first.
Queueing catalog content without a subscription gate Check canPlayCatalogContent ; offer subscription only when canBecomeSubscriber .
Using SystemMusicPlayer for app owned playback Use ApplicationMusicPlayer ; the system player changes the Music app's global queue.
Publishing Now Playing metadata once Refresh it on track, duration, rate, and elapsed time changes.
Registering unsupported remote commands Disable them; supported handlers must perform the action and return .success .
Review Checklist
[ ] MusicKit App Service enabled for the app's explicit bundle ID
[ ] NSAppleMusicUsageDescription added to Info.plist
[ ] MusicAuthorization.request() called before any MusicKit access
[ ] Subscription checked before attempting catalog playback
[ ] canBecomeSubscriber checked before presenting a subscription offer
[ ] hasCloudLibraryEnabled checked before library writes
[ ] ApplicationMusicPlayer used (not SystemMusicPlayer ) for app scoped playback
[ ] Background audio mode enabled if music plays in background
[ ] Now Playing info updated on every track change (for custom audio)
[ ] Remote command handlers return .success for supported commands
[ ] Unsupported remote commands disabled with isEnabled = false
[ ] Artwork provided in Now Playing info for Lock Screen display
[ ] Elapsed playback time updated periodically for scrubber accuracy
[ ] Subscription offer presented when user lacks Apple Music subscription
References
Extended patterns (SwiftUI integration, genre browsing, playlist management): [references/musickit patterns.md](references/musickit patterns.md)
[MusicKit framework](https://sosumi.ai/documentation/musickit)
[Using automatic developer token generation for Apple Music API](https://sosumi.ai/documentation/musickit/using automatic token generation for apple music api)
[MusicAuthorization](https://sosumi.ai/documentation/musickit/musicauthorization)
[ApplicationMusicPlayer](https://sosumi.ai/documentation/musickit/applicationmusicplayer)
[MusicCatalogSearchRequest](https://sosumi.ai/documentation/musickit/musiccatalogsearchrequest)
[MusicSubscription](https://sosumi.ai/documentation/musickit/musicsubscription)
[canPlayCatalogContent](https://sosumi.ai/documentation/musickit/musicsubscription/canplaycatalogcontent)
[canBecomeSubscriber](https://sosumi.ai/documentation/musickit/musicsubscription/canbecomesubscriber)
[hasCloudLibraryEnabled](https://sosumi.ai/documentation/musickit/musicsubscription/hascloudlibraryenabled)
[MusicCatalogChartsRequest initializer](https://sosumi.ai/documentation/musickit/musiccatalogchartsrequest/init(genre:kinds:types:))
[musicSubscriptionOffer(isPresented:options:onLoadCompletion:)](https://sosumi.ai/documentation/swiftui/view/musicsubscriptionoffer(ispresented:options:onloadcompletion:))
[MPRemoteCommandCenter](https://sosumi.ai/documentation/mediaplayer/mpremotecommandcenter)
[MPNowPlayingInfoCenter](https://sosumi.ai/documentation/mediaplayer/mpnowplayinginfocenter)
[NSAppleMusicUsageDescription](https://sosumi.ai/documentation/bundleresources/information property list/nsapplemusicusagedescription)