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

Replies

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,

  • Thank you for the response. I successfully requested authorization, and there is no more permissionDenied error. But it's still giving me the .developerTokenRequestFailed error. In the video it says all I need to do is register an AppID token on my developer portal. I did that, checked the MusicKit service box and copied Bundle ID into my Xcode project's Bundle Identifier.

    2021-06-11 08:29:47.684453-0700 MusicPlayground[85583:993511] [DataRequesting] Failed retrieving MusicKit tokens: Error Domain=ICErrorDomain Code=-8200 "Media API Token Service's response was invalid (status code: Unauthorized (401))." UserInfo={NSDebugDescription=Media API Token Service's response was invalid (status code: Unauthorized (401))., NSUnderlyingError=0x600003869770 {Error Domain=AMSErrorDomain Code=301 "Invalid Status Code" UserInfo={NSLocalizedDescription=Invalid Status Code, AMSURL=https://sf-api-token-service.itunes.apple.com/apiToken?REDACTED, AMSStatusCode=401, AMSServerPayload={     status = verificationFailure; }, NSLocalizedFailureReason=The response has an invalid status code}}}. Throwing .developerTokenRequestFailed. 2021-06-11 08:29:47.684730-0700 MusicPlayground[85583:993511] [DataRequesting] Failed retrieving tokens for MusicDataRequest.Context(url: https://api.music.apple.com/v1/catalog/us/genres). Error = .developerTokenRequestFailed. .developerTokenRequestFailed
  • Ok, so it's not just me! So Apple went from an incredibly complicated authentication mechanism for MusicKit that presumably hardly anyone used, to a ridiculously simple one that doesn't work and provides no details as to the cause of the problem.

  • Hello @jevonmao1,

    Thank you for letting us know about this error you're encountering while performing a MusicKit request.

    We would definitely like to investigate this further, but to do that, we need to get a sysdiagnose from your device. Would you mind creating a new ticket on Feedback Assistant about this issue, including a sysdiagnose?

    Thank you very much in advance for your help.

    Best regards,