当用户允许访问媒体库时,我需要在我的应用中重新加载音乐列表,并且我想在用户不允许访问时显示通知。我怎样才能得到两个回调?
对于请求访问权限,我只是将此行添加到info.plist NSAppleMusicUsageDescription
答案 0 :(得分:2)
您需要获得访问MPMediaLibrary的权限,这是您可以申请的方式
<强>目标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
}
}