Home / IOS Development / iOS – Disable iTunesStore Access for SwiftUI App – Get Rid of “iTunesStore Account Retrieval Errors”

iOS – Disable iTunesStore Access for SwiftUI App – Get Rid of “iTunesStore Account Retrieval Errors”



In my app I get access local iTunes music using MPMediaQuery. I just need to ask for local music on my iOS device and do not need access to Apple Music / iTunesStore.

Quick version: 5
iOS target: 1

4.x

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

NSAppleMusicUsageDescription
Music player needs access to your music

This is my first 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 I run this code on my iPhone, I get these warnings in 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 disable the iTunesStore / Apple Music features for my app?


Source link