Hey, I've been trying to fetch my Apple Music recently played songs for an app I'm working on, and I want to access the lastPlayedDate field. If I'm not mistaken, this field should exist for a Song according to Apple's documentation: https://developer.apple.com/documentation/musickit/song/lastplayeddate
However, whenever I try to fetch this data, the lastPlayedDate field is always nil. All the other data I'm looking for, however, seems to fetch without issue. Here's the code I'm using:
//Request as described in Apple MusicKit
//https://developer.apple.com/documentation/musickit/musicrecentlyplayedrequestable
var request = MusicRecentlyPlayedRequest<Song>()
request.limit=30
do {
let response = try await request.response()
let songs = response.items.compactMap { song -> RecentlyPlayedSong? in
let songName = song.title
let songArtist = song.artistName
let songAlbum = song.albumTitle
let artwork: MusicArtworkType
let preview_url = song.previewAssets?.first?.url?.absoluteString
if let appleMusicArtwork = song.artwork {
print("Found a song, \(song) with lastPlayedDate \(song.lastPlayedDate)")
artwork = .AppleMusic(appleMusicArtwork)
return RecentlyPlayedSong(name: songName, artist: songArtist, album: songAlbum, artwork: artwork, preview_url: preview_url, lastPlayedDate: song.lastPlayedDate ?? Date())
}
I'm trying to map the response into a custom struct I made, but here's a sample of what's getting printed to the logs:
Found a song, Song(id: "1676362342", title: "pwdr Blu (feat. Brother.)", artistName: "Kx5, deadmau5 & Kaskade") with lastPlayedDate nil
Found a song, Song(id: "881289980", title: "Worlds Apart (feat. Kerli)", artistName: "Seven Lions") with lastPlayedDate nil
Found a song, Song(id: "1501540431", title: "What’s Done Is Done", artistName: "Seven Lions & HALIENE") with lastPlayedDate nil
Even though I just listened to these songs a a few minutes ago. Anyone ever run into this issue before? Any settings I need to look at changing to get this to show?