苹果改变的东西在他们
NSString和
NSURL图书馆在其最新版本(iOS版9),但这些方法都可以从iOS版4.您可以检查有关苹果论坛帖子的更多细节。
要修复此错误,您需要更改代码,例如:
斯威夫特2:
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!){ let imageUrl = editingInfo[UIImagePickerControllerReferenceURL] as! NSURL let imageName = imageUrl.lastPathComponent let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .UserDomainMask, true).first as String! let photoURL = NSURL(fileURLWithPath: documentDirectory) let localPath = photoURL.URLByAppendingPathComponent(imageName!) let image = editingInfo[UIImagePickerControllerOriginalImage]as! UIImage let data = UIImagePNGRepresentation(image) data!.writeToFile(localPath.absoluteString, atomically: true) self.dismissViewControllerAnimated(true, completion: nil);}斯威夫特3:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){ let imageUrl = info[UIImagePickerControllerReferenceURL] as! NSURL let imageName = imageUrl.lastPathComponent let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! let photoURL = NSURL(fileURLWithPath: documentDirectory) let localPath = photoURL.appendingPathComponent(imageName!) let image = info[UIImagePickerControllerOriginalImage]as! UIImage let data = UIImagePNGRepresentation(image) do { try data?.write(to: localPath!, options: Data.WritingOptions.atomic) } catch { // Catch exception here and act accordingly } self.dismiss(animated: true, completion: nil);}参考:
- lastPathComponent
- URLByAppendingPathComponent:



