2
如何防止用戶在UIImagePickerContoroller中兩次選取相同的圖像以避免重複?防止在UIImagePickerController中選取兩張相同的照片
我試着用URLReference做它,但它不工作,所以我猜它不是這樣。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let url = info[UIImagePickerControllerReferenceURL] as? NSURL{
if photosURL.contains(url){
Utilities.showMessage(message: "photo Uploaded already", sender: self, title: ErrorTitle.FRIENDS, onDismissAction: nil)
} else {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
photos.append(pickedImage)
}
}
}
dismiss(animated: true, completion: nil)
}
感謝,
爲imagePicker添加完成的代碼。 –
'info [UIImagePickerControllerReferenceURL]'應該對每個圖像都是唯一的,所以你可以保留它來檢查它是否已經被選中 – xmhafiz
已經試過了,當我檢查photosURL.contains(url)是否返回false –