当用户允许访问媒体库时,我需要在我的应用中重新加载音乐列表,并且当用户不允许访问时,我想显示一条通知。如何获得两个回调?
为了请求访问,我刚刚将此行添加到了info.plist NSAppleMusicUsageDescription
中
最佳答案
您需要请求访问MPMediaLibrary的权限,这是您可以请求的方式
Objective-C
[MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus authorizationStatus) {
if ( authorizationStatus == MPMediaLibraryAuthorizationStatusAuthorized ) {
// Reload your list here
} else {
// user did not authorize
} }];
迅捷
MPMediaLibrary.requestAuthorization { (status) in
if status == .authorized {
// Reload your list here
} else {
// user did not authorize
}
}