3 回答
TA贡献1779条经验 获得超6个赞
您需要明确的Objective-C参考: @objc
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
image = chosenImage
self.performSegue(withIdentifier: "ShowEditView", sender: self)
dismiss(animated: true, completion: nil)
}
TA贡献1828条经验 获得超3个赞
我找到了解决方案。由于以下两个原因,导致出现此错误。
首先,我们需要调用此方法进行授权
授权码
func checkPermission() {
let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus() switch photoAuthorizationStatus {
case .authorized: print("Access is granted by user")
case .notDetermined: PHPhotoLibrary.requestAuthorization({
(newStatus) in print("status is \(newStatus)") if newStatus == PHAuthorizationStatus.authorized { / do stuff here */ print("success") }
})
case .restricted: / print("User do not have access to photo album.")
case .denied: / print("User has denied the permission.")
}
}
正确的方法调用 didFinishPickingMediaWithInfo
错误:
private func imagePickerController( picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
}
对
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
}
希望此解决方案可以帮助您解决此错误。
如果对您有用,请别忘了将其标记为正确,这将有助于其他人找到正确的方法。
TA贡献1883条经验 获得超3个赞
我找到了!它试图告诉您您没有“照片”的#import <Photos/Photos.h>授权。例如,需要在Objective-C中包括和请求这样的授权。
希望这可以节省您一些时间。我花了整整两天的时间进行调试!
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
switch (status) {
case PHAuthorizationStatusAuthorized:
NSLog(@"PHAuthorizationStatusAuthorized");
break;
case PHAuthorizationStatusDenied:
NSLog(@"PHAuthorizationStatusDenied");
break;
case PHAuthorizationStatusNotDetermined:
NSLog(@"PHAuthorizationStatusNotDetermined");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"PHAuthorizationStatusRestricted");
break;
}
}];
我相信有人可以告诉您如何在Swift中执行相同的操作。
- 3 回答
- 0 关注
- 894 浏览
添加回答
举报