iOS App's Documents directory contents lost after Restore from Backup - ios

I am working on an App that requires a folder structure in the Documents directory to access images and videos in various modules. These are stored there using a download process and it works fine.
While testing I restored the app using iTunes. I found that none of the downloaded assets where visible. After some searching I used the Download Container option in the Devices window of Xcode to view the package contents of my App.I found that all files that where stored in the documents directory were present, but none of the folders were present. I think this is what causes the issue.
I tried another similar project, but the folder structure was intact.

Related

How do you persist image references across app updates on iOS devices

I have developed a Flutter app that captures images using the camera and I store references to the image files using Shared Preferences.
When I upgrade the iOS app, the Shared Preference filename persists as expected, but the image no longer displays on the iOS device (and no longer seems to exist) File(_imageFileRef).existsSync() is false
For example, on iPhone, the image file is saved as
/private/var/mobile/Containers/Data/Application/580A9879-23CD-413D-A785-DB910673DF74/tmp/some_guid_image_name.jpg
When the app is upgraded, this file no longer seems to exist.
Where should I be saving the image files to in iOS so that they persist across upgrades?
The functionality works perfectly on Android devices.
Having received no answers, I delved a bit deeper and discovered that...
...the tmp directory in which the images are being written is for temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running. The contents of this directory are not backed up by iTunes or iCloud.
So in order for the data to persist over app updates, I need to be writing to the Documents directory
Info obtained from here

How to check iOS sandbox container files locations?

I've downloaded the sandbox of my APP from a connected test device using Xcode. After opening it using "finder", I see the following folders as expected.
Documents
Library
StoreKit
tmp
But when I look into the above directories I can find none of the files that are used by the APP. For example, the APP uses over 40 jpg files, why are they not being shown inside the downloaded sandbox package at all?
As Philip Mills has suggested, it is normal not to have the jpg files in the sandbox folders as they are bundled in the app.
Files need to be explicitly put in the sandbox folders in order to be there.

Can you access previous /var files from new compiles of the same app?

Our app downloads a bunch of video files and allows the user to view them. We've noticed that we can download and play the files with no issues at all. But then if an update is pushed or we use Xcode to push a new app over the old one (same version) it will report that the video cannot be found. This is despite the the fact that we can see the video there, in the same folder and folder ID we're looking for has not changed. Is there something happening behind the scenes with local storage for iOS app files that makes them inaccessible after an update?
Example:
/var/mobile/containers/data/application/{same id}/documents/

Having a bit of trouble with copying a local file on iOS

Having only worked with Android/web dev before I am having a hard time figuring out where in the world my file should be getting copied to in iOS. After reading the file browser documentation on the iOS developer resource page it says that each app is an "island" which contains its own folder system. If I want to have my user be able to copy a file from my app's sdk to their iOS device, where should I put it?
I downloaded a file browser app from the app store on my iOS testing device but am I right in thinking that there is no global file browsing system?
I am using a Cordova plugin called Asset2sd which works perfectly for me in Android, getting the root storage folder and downloading the file to there. It has no iOS alternative so I'm going to have to figure something else out, I just need to know where to start. Do I have to have the user access my app's internal files somehow? Can I create a folder for them to look in when they download my app? Some documentation or something would be wonderful. I am totally lost.
Thanks!
You're right. Apps don't have access to the global file system. Each app only has access to their own app directory. Here's in-depth information on Sandboxing: https://developer.apple.com/app-sandboxing/
In your app's sandbox, you basically can manage files as you want, i.e. download, copy, move, delete, etc. So you can create a folder Downloads in your apps documents directory and then display the contents of this folder for instance in a table view.
Related documentation/links:
https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html
https://stackoverflow.com/a/6907432/967327
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/iPhoneAppProgrammingGuide.pdf

retain program data in iOS app while updating and sync to iCloud

When a new upgrade is released and installed on iOS, which folders / files are left untouched by the upgrade process? There are several folders; Library, Caches, Preferences, Documents.
Normally Application Support Directory is not created by default. What happen to AS folder during upgrade?
I learn that all data in Documents folder will copy to iTunes or iCloud by default. Is that true?
If I create my own CoreData db to persist, where should I keep?
Your best bet is to read the first half (which pertained to iOS) of this document from Apple:
In my experience, I put Core Data db in Documents folder if the iTunes File Sharing feature was not enabled on your app. Otherwise create a folder in the Library folder called Application Support or anything name, etc. With iTunes File Sharing enabled, user can accidentally delete any files in the Documents folder.
During the upgrade, the contents of Library and Documents folder are retained.

Resources