在此处输入代码我有这样的代码用于权限处理程序:
func authorizeMediaLibrary(forStatus status: MPMediaLibraryAuthorizationStatus) -> Void{
switch status {
case .authorized:
self.initializeMedia()
case .denied:
guard let settingUrl = URL(string: UIApplication.openSettingsURLString) else {return}
if UIApplication.shared.canOpenURL(settingUrl) {
UIApplication.shared.open(settingUrl) { success in}
}
case .notDetermined:
MPMediaLibrary.requestAuthorization { stat -> Void in
if stat == .authorized {
self.media.getMediaQueryCollection()
self.allMediaItems = self.media.getMPMediaItemCollection()
}
}
default:
break
}
}
我什至试过这个:
func getAuthrization(completionHandler:@escaping (Bool) -> Void) {
if MPMediaLibrary.authorizationStatus() == .authorized {
completionHandler(true)
} else {
MPMediaLibrary.requestAuthorization() { completionHandler($0 == .authorized) }
}
}
但是他们两个都没有帮助我,弹出窗口会显示,但是在接受后,它没有调用回调,也没有刷新我的视图来填充数据。我知道这是关于刷新我的视图,因为当我再次运行它,我得到了结果,并且权限状态更改为已授权。
问题: