[英]Save image file to app documents directory in Swift. Does the url to App document directory change even when deployed on the device?
Below are the two functions which I use in the picker view controller to save the file in the App documents directory. 以下是我在选择器视图控制器中使用的两个功能,用于将文件保存在App文档目录中。 And save the url in the local DB & display the image using UIImage(contentsOfFile: ImagePathString)
并将网址保存在本地数据库中,并使用UIImage(contentsOfFile:ImagePathString)显示图像
Everything works well as until this point however as soon as i re-run the simulator images does not show up. 一切正常,直到这一点,但是,一旦我重新运行模拟器图像就不会显示。 I believe its because the app directory keeps changing every time its run on the simulator.
我相信这是因为应用程序目录每次在模拟器上运行时都会不断变化。 My question if its the same when deployed on the device?
我的问题是在设备上部署时是否相同?
func getDocumentsDirectory() -> NSString {
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0]
return documentsDirectory
}
//Below function is used in imagePickerController
if let data = UIImagePNGRepresentation(modifiedImage!) {
let filename = getDocumentsDirectory().stringByAppendingPathComponent("\(NSDate()).png")
data.writeToFile(filename, atomically: true)
pathImage = filename
print(pathImage)
}
Yes url to App documents folder may change when the app is deployed on the device. 是当在设备上部署应用程序时,“应用程序文档”文件夹的url可能会更改。 Refer below link Technical Note TN2406 .
请参阅下面的链接技术说明TN2406 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.