Swift 4 . A simple solution is as follows, and you can change it to include other alternatives, but in my case it was access or nothing.
private func checkPermissionForMusic() -> Bool { switch MPMediaLibrary.authorizationStatus() { case .authorized: return true default: return false } }
Caution about using the above solutions - they are executed as a block statement and do not return a value ( return true or return "authorised" ) in the same thread; the result is processed in the background thread. If you decide to use the above sentences, use a handler (call another function) to handle the expected result. This decision, on the other hand, immediately tells you whether you have access or not. No waiting required.
Additional information is available at Apple Docs.
source share