本文介绍了检测媒体库ios的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用中,我想检测一下,如果用户是否允许他的媒体库。当系统弹出询问或稍后设置时,用户可能会拒绝媒体库权限。有没有办法检测媒体库权限的状态?
In my app, I want to detect that if user give the permission to his media library or not. User may denied media library permission when system popup ask or later from setting. Is there any way to detect the status of media library permission?
这是我的代码,可以访问歌曲列表。
Here is my code that access list of songs.
MPMediaQuery *everything = [MPMediaQuery songsQuery];
NSArray *songArray = [everything items];
请参阅下面的屏幕截图,用户可以更改媒体库权限。
Please see below screenshot where user can change Media Library permissions.
推荐答案
-(void) checkMediaLibraryPermissions {
[MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status){
switch (status) {
case MPMediaLibraryAuthorizationStatusNotDetermined: {
// not determined
break;
}
case MPMediaLibraryAuthorizationStatusRestricted: {
// restricted
break;
}
case MPMediaLibraryAuthorizationStatusDenied: {
// denied
break;
}
case MPMediaLibraryAuthorizationStatusAuthorized: {
// authorized
break;
}
default: {
break;
}
}
}];
}
这篇关于检测媒体库ios的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!