contributors | originalURL |
---|---|
Jeehut |
-
MusicKit allows access to Apple Music API to search for content
-
It also allows for playback in third party apps (user needs to be subscribed)
-
Music items:
Album
with attributes, relationships and associations -
Use
album.with([.artists, .tracks, .relationAlbums])
for fetching relationships -
All calls are using Swift concurrency, so
try await
needed on call site -
Playback integrates with system, so media controls in lock screen work for example
-
Requests done via
MusicCatalogResourceRequest<Album>(matching:equalTo:)
-
Then just call
try await request.response()
on the request object -
Contributor comment: The networking structure here is interesting, maybe a new platform best practice!?
-
User consent is needed to access music listening history & music library (separately)
-
Access is given once per device & per app, dialog has “yes” / “no” options
-
As always, a usage description must be provided in
Info.plist
file -
Use
MusicAuthorization.request()
(async method) to get access inMusicKit
-
API token for Apple Music API is automated by Xcode, just check the box in Connect
-
3 information to check regarding subscription capabilities:
- can play catalog content, has cloud library enabled & can become subscriber
-
MusicSubscription.subscriptionUpdates
informs app when user subscribes -
Two players available,
SystemMusicPlayer
integrates with system more,ApplicationMusicPlayer
allows for more customization for the app like playback queue -
Apple Music free trial can be started right within third party apps via system sheet
-
New Affiliate program to get bonus if users subscribe via 3rd party app
-
Class supports album customization, named
MusicSubscriptionOffer
(.Options
) -
Possible use cases: background music in games, music during workouts, social media