I'm trying to save a label on top of an image using .WriteToFile .
Here's the code I'm using to save the image :
let selectedImage: UIImage = image.image!
let fileManager = NSFileManager.defaultManager()
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let filePathToWrite = "\(paths)/User_Profile_Image.png"
let imageData: NSData = UIImagePNGRepresentation(selectedImage)!
let jpgImageData = UIImageJPEGRepresentation(selectedImage, 1.0)
fileManager.createFileAtPath(filePathToWrite, contents: jpgImageData, attributes: nil)
// Check file saved successfully
let getImagePath = (paths as NSString).stringByAppendingPathComponent("User_Profile_Image.png")
if (fileManager.fileExistsAtPath(getImagePath)) {
print("FILE AVAILABLE");
} else {
print("FILE NOT AVAILABLE");
}
I'm trying to retrieve it by :
if let pdfURL = NSBundle.mainBundle().URLForResource("User_Profile_Image", withExtension: "png", subdirectory: nil, localization: nil),data = NSData(contentsOfURL: pdfURL), baseURL = pdfURL.URLByDeletingLastPathComponent {
let webView = UIWebView(frame: CGRectMake(20,20,self.view.frame.size.width-40,self.view.frame.size.height-40))
print("Hello World")
webView.loadData(data, MIMEType: "application/pdf", textEncodingName:"", baseURL: baseURL)//application/
self.view.addSubview(webView)
}
But it isn't working. Any ideas?