For my app that heavily uses both ShazamKit and MusicKit, I need to be able to check if the matched song is in the user's library or not.
I couldn't find an easy way to do this with MusicKit so I first then turned to the Apple Music API as they introduced the new parameter
?relate=library
during this year's WWDC.
When I first tried it, it worked as expected, and was very happy to have gotten it to work. However, it stopped working lately and now I turned to use MPMediaLibrary
as that still works but is a lot slower in performance.
Anyone has any idea why the ?relate=library
stopped working for me or know a better way to check if the Song
exists in the user's library?
func checkInLibrary(from appleMusicID: String) async {
do {
let countryCode = try await MusicDataRequest.currentCountryCode
let libURL = URL(string: "https://api.music.apple.com/v1/catalog/\(countryCode)/songs/\(appleMusicID)?relate=library")!
let request = MusicDataRequest(urlRequest: URLRequest(url: libURL))
let dataResponse = try await request.response()
print(dataResponse.debugDescription)
}
catch { // I'm handling errors here }}