我正在开发一个将用户创建的图像保存到照片库的应用程序。我需要为每个保存的图像附加一个用户名,以便我以后可以回忆起这些。据我了解(请纠正我,如果我错了),如果我保存到照片库,我无法更改实际的文件名,所以解决这个问题的方法是更改修改元数据并写入用户名例如,描述。但是,我完全坚持如何在Swift中实现这一点,我到处寻找答案。我必须保存每个UIImage的代码如下:我有保存选项和警报视图中显示的用户名输入。
// Create the alert controller
let alertController = UIAlertController(title: "Finished?", message: "Is this your attempt?", preferredStyle: .Alert)
// Create the actions
let okAction = UIAlertAction(title: "Yes, save", style: UIAlertActionStyle.Default) {
UIAlertAction in
NSLog("OK Pressed")
if let image = self.mainImageView.image{
UIImageWriteToSavedPhotosAlbum(image,self,Selector("image:withPotentialError:contextInfo:"),nil)
}
}
let cancelAction = UIAlertAction(title: "No", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
self.mainImageView.image = nil
}
alertController.addTextFieldWithConfigurationHandler { (textField : UITextField!) -> Void in
textField.placeholder = "Enter User Name"
self.inputTextField = textField
}
// Add the actions
alertController.addAction(okAction)
alertController.addAction(cancelAction)
// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)
我有另一个图像功能,如下所示:
func image(image: UIImage, withPotentialError error: NSErrorPointer, contextInfo: UnsafePointer<()>) {
NSLog("\(self.inputTextField.text)")
let alertController = UIAlertController(title: "Success!", message:"Your image was saved", preferredStyle: .Alert)
//Some additional code here, specific to another part of the app that has to occur after the image is saved
self.presentViewController(alertController, animated: true){}
}
此代码用于保存图像,但是我完全不知道如何向图像的元数据添加任何内容。如果有人有任何建议或建议,将不胜感激,如果有任何不清楚的地方请告诉我,我可以在评论中进行编辑或澄清。