authorizationStatus()关于MPMediaLibrary访问

时间:2017-05-18 06:20:57

标签: ios swift2 itunes mpmediaitem mpmediaquery

我想访问媒体库以显示歌曲列表。所以在前提条件下,我正在检查媒体库的授权状态。当我们在权限警报中选择“不允许”时,将授权状态设置为.Denied,但应用程序可以获取媒体项目。没有媒体权限我们也可以访问库吗?如果是,在代码级别需要媒体权限?以下是代码。

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
        }
    }
}

0 个答案:

没有答案