Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios authorizationStatus()关于MPMediaLibrary访问_Ios_Swift2_Itunes_Mpmediaitem_Mpmediaquery - Fatal编程技术网

Ios authorizationStatus()关于MPMediaLibrary访问

Ios authorizationStatus()关于MPMediaLibrary访问,ios,swift2,itunes,mpmediaitem,mpmediaquery,Ios,Swift2,Itunes,Mpmediaitem,Mpmediaquery,我想访问媒体库以显示歌曲列表。因此,我正在检查媒体库的授权状态。当我们在权限警报中选择“不允许”时,获得的授权状态为.Denied,但应用程序可以获取媒体项目。如果没有媒体权限,我们也可以访问库吗?如果是,代码级别的媒体权限需要什么?下面是代码 func checkMediaLibraryPermissions() { if #available(iOS 9.3, *) { func requestAuthorization() { MPMedia

我想访问媒体库以显示歌曲列表。因此,我正在检查媒体库的授权状态。当我们在权限警报中选择“不允许”时,获得的授权状态为
.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
        }
    }
}