1

I want to access the media library to display songs list. So on precondition I am checking the authorization status for the media library. When we go for "Don't Allow" in the permission alert, getting the authorization status as .Denied, But app can able to get the media items. Without media permissions also can we access the library? If yes what is need of media permissions on code level? Below is the code.

func checkMediaLibraryPermissions() {
    if #available(iOS 9.3, *) {
        func requestAuthorization() {
            MPMediaLibrary.requestAuthorization { (status) in
                switch status {
                case .Authorized:
                // Go for the further actions
                case .NotDetermined: break // We are already request the authorization above
                case .Denied,
                .Restricted:
                    let qrySongs = MPMediaQuery.songsQuery()
                    debugPrint(qrySongs.count)

                    // Require to show the alert about the permission enable
                }
            }
        }

        let authorizeStatus = MPMediaLibrary.authorizationStatus()
        switch authorizeStatus {
        case .Authorized:
            // Go for the further actions               
        case .NotDetermined:
            requestAuthorization()
        case .Restricted,
             .Denied:
            let qrySongs = MPMediaQuery.songsQuery()
            debugPrint(qrySongs.count)

            // Require to show the alert about the permission enable
        }
    }
}
Vishnuvardhan
  • 5,081
  • 1
  • 17
  • 33

0 Answers0