I want to use the Apple Music API to get album artwork for songs playing on the radio. The API seems to be easy and straightforward (for web and app). The documentation says that we need to request user authorization only if we want to access their library. All I want to do is to perform a simple search with the provided terms.
I tried using the MusicCatalogSearchRequest
using this code:
var songRequest = MusicCatalogSearchRequest(term: song, types: [Song.self])
songRequest.limit = 1
let response = try await songRequest.response()
guard let url = response.songs.first?.artwork?.url(width: width, height: height) else {
throw RadioImageError.notFound
}
return url
I get the following error in the logs
[DataRequesting] Failed to fetch current country code because the music authorization status is set to .notDetermined. Please make sure to request authorization for your app to access the user's Apple Music data using MusicAuthorization.request().
I am not able to supply the store front otherwise.
Then I tried constructing the URL myself and then calling MusicDataRequest
.
I only get a similar error, that the user needs to authorize access first.
And I added Music as a service to my bundle identifier.
All the best, Alex