Error: connection to service on pid 0 named com.apple.itunescloudd.xpc

I am following along the session Meet MusicKit, and when I try to call this snippet of code (directly copied from session):

struct MyGenresResponse: Decodable {
            let data: [Genre]
        }

        let countryCode = try await MusicDataRequest.currentCountryCode

        let url = URL(string: "https://api.music.apple.com/v1/catalog/\(countryCode)/genres")!



        let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))

        let dataResponse = try await dataRequest.response()



        let decoder = JSONDecoder()

        let genresResponse = try decoder.decode(MyGenresResponse.self, from: dataResponse.data)

        print("\(genresResponse.data[9])")

I run into a problem. The code is not working as intended and the console gives me an error that looks like:

I have registered an AppID for my app and enabled MusicKit capability.

2021-06-10 16:43:23.166876-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 1 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.174082-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 2 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.181243-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 3 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.183420-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 4 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.184647-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 5 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.187290-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 6 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.190262-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 7 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.192981-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 8 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.194085-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 9 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.195300-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService - XPC Error retrieving endpoint [Attempt 10 of 10] - service=cloudStatusMonitor[4] - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.195354-0700 MusicPlayground[1179:93172] [Default] <ICCloudServerListenerEndpointProvider: 0x281f6a960>: listenerEndpointForService [done with error] - service=cloudStatusMonitor[4] - endpoint=(null) - error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}

2021-06-10 16:43:23.196135-0700 MusicPlayground[1179:93172] [Default] <ICCloudServiceStatusMonitor: 0x28313a300>: Encountered error while requesting storefront country code. Error Domain=ICErrorDomain Code=-7010 "Failed to get listener endpoint for cloud service status monitor." UserInfo={NSDebugDescription=Failed to get listener endpoint for cloud service status monitor., NSUnderlyingError=0x281144750 {Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}}} Underlying error: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.itunescloudd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.itunescloudd.xpc}.

.permissionDenied

Hello @jevonmao1,

Thanks for the feedback.

The error you're getting back here is MusicTokenRequestError.permissionDenied.

Before you use any other MusicKit API, make sure to use the MusicAuthorization API to request authorization for your app to access the Apple Music data of the user.

To do that, you'll need to include an entry in your Info.plist named NSAppleMusicUsageDescription; this entry typically shows up in Xcode's Property List editor as Privacy - Media Library Usage Description.

This is explained in the section titled Privacy and user consent of our Meet MusicKit for Swift session.

I hope this helps.

Best regards,

Error: connection to service on pid 0 named com.apple.itunescloudd.xpc
 
 
Q