iOS 14 StoreKit - SKCloudServiceController's requestusertoken not being called properly

I am trying to play songs on iOS 14 using Apple Music API. I have the developer's token, and I have asked for the permission for accessing the user's apple music.

However, when I call requestusertoken api, its closure never gets called, so obviously I don't receive anything from the request - not even an error. It's driving me crazy!!

Here is my code. What am I doing wrong?

Code Block swift
func getUserToken() -> String {
var userToken = String()
let lock = DispatchSemaphore(value: 0)
SKCloudServiceController().requestUserToken(forDeveloperToken: developerToken) { (receivedToken, error) in
guard error == nil else { return }
if let token = receivedToken {
userToken = token
lock.signal()
}
}
lock.wait()
return userToken
}


I'm having the exact same issue, did you ever figure out what was wrong?
I'm stuck on the same thing. One thing I did notice though, it looks like the requestUserToken call completes just fine (validated by adding a print line after userToken=token) if you remove/comment the lock.wait() line (granted this won't fix the problem because getUserToken would return a blank string since it doesn't wait for the call to complete).

Based on this, my hunch is that the lock is preventing the requestUserToken call from executing or completing. This is where I'm stuck at the moment - how to either get requestUserToken to work with the lock or find an alternative to the lock pattern.
I've submitted a formal request to help me solve this same issue. I will post here with any updates!
iOS 14 StoreKit - SKCloudServiceController's requestusertoken not being called properly
 
 
Q