简体   繁体   English

将图像文件保存到Swift中的应用程序文档目录中。 即使部署在设备上,App文档目录的url也会更改吗?

[英]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.

相关问题 swift:保存文件文件目录 - swift: save file document directory 将文件保存在 swift 3 的文档目录中? - Save file in document directory in swift 3? 删除app文档目录中的图像 - Delete image in app document directory 如果我将使用Swift 3再次运行该应用程序,则该图像在文档目录中不存在 - Image is not existing in document directory if I will run the app again using Swift 3 尝试将jpeg保存到应用程序的Documents目录 - trying to save jpeg to Documents directory of app 在Swift中打开我的iOS应用程序的文档目录 - open documents directory of my iOS app in Swift 如何将图像保存在文档目录中并在 Swift 中获取它 - How to save image in document directory and fetch it in Swift 使用带有设备的avfoundation将Swift会话保存在文档目录中 - save Capture session in documents directory using swift with avfoundation from device 数据库中存在数据库但不存在于设备构建中(将文件从App Bundle复制到Swift中的文档目录) - Database present in simulator but not on device build (Copying files from App Bundle to Documents Directory in Swift) 卸载应用程序时,有没有不删除文档目录的方法? - Is there a way to not erase the documents directory when uninstalling the app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM