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 關注
- 932 瀏覽
添加回答
舉報