Tuesday, 6 October 2020

Disable iTunesStore access for SwiftUI app - get rid of "Error retrieving iTunesStore accounts" warnings

Within my app, I'm accessing local iTunes music using MPMediaQuery. I only need to query for local music on the iOS device and don't need any access to Apple Music / iTunesStore.

Swift version: 5
iOS target: 14.x

To get access to local music, I added this to my Info.plist:

<key>NSAppleMusicUsageDescription</key>
<string>Music player needs access to your music</string>

This is my initial Swift code:

import MediaPlayer

struct Track {
    let url: URL
    let artist: String?
    let title: String?
}

class ViewModel: ObservableObject {
    @Published var tracks: [Track] = [Track]()
    
    init() {
        MPMediaLibrary.requestAuthorization { status in
            if status == .authorized {
                DispatchQueue.main.async {
                    let mediaItems: [MPMediaItem] = MPMediaQuery.songs().items!
                    
                    for item in mediaItems {
                        self.tracks.append(Track(url: item.assetURL!, artist: item.artist, title: item.title))
                    }
                }
            }
        }
    }
}

struct ContentView: View {
    @ObservedObject var viewModel = ViewModel()
    
    var body: some View {
        VStack() {
            List {
                ForEach(self.viewModel.tracks, id: \.url) { track in
                    VStack(alignment: .leading) {
                        Text(track.artist ?? "")
                        Text(track.title ?? "")
                    }
                }
            }
        }
    }
}

When running this code on my iPhone, I'm getting these warnings within the Xcode logs:

2020-09-29 15:42:37.395885+0200 Playground1[12541:1125769] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2020-09-29 15:42:37.396041+0200 Playground1[12541:1125769] [iTunesCloud] ACAccountStore 0x280597090 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"
2020-09-29 15:42:37.397384+0200 Playground1[12541:1125769] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2020-09-29 15:42:37.397491+0200 Playground1[12541:1125769] [iTunesCloud] ACAccountStore 0x280597090 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"
2020-09-29 15:42:37.407044+0200 Playground1[12541:1125769] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2020-09-29 15:42:37.407147+0200 Playground1[12541:1125769] [iTunesCloud] ACAccountStore 0x280597090 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"
2020-09-29 15:42:37.407200+0200 Playground1[12541:1125769] [iTunesCloud] ACAccountStore 0x280597090 - Error retrieving local store account. err=Error Domain=com.apple.accounts Code=9 "(null)"
2020-09-29 15:42:37.407250+0200 Playground1[12541:1125769] [iTunesCloud] [ICUserIdentityStore] Failed to fetch local store account with error: Error Domain=com.apple.accounts Code=9 "(null)".

How can I suppress these warnings? Can I just completely disable any iTunesStore/Apple Music capability for my app?



from Disable iTunesStore access for SwiftUI app - get rid of "Error retrieving iTunesStore accounts" warnings

No comments:

Post a Comment