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

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/

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

Where is the file saved by Cordova File plugin on iOS

I am writing a PDF file on an iPhone running iOS 11, using Cordova File Plugin (in Ionic). The file is created successfully (e.g. in a location like file:///var/mobile/Containers/Data/Application/CDFC4E19-082F-4878-9168-F4A735CDAFEB/Documents or file:///var/mobile/Containers/Data/Application/DA918690-B345-438A-B26D-2EA21D618341/Library/Cloud), but then I can't find the file on the iPhone. I have tried setting the directory to cordova.file.documentsDirectory as well as cordova.file.syncedDataDirectory. When I run the Files app on the iPhone, it shows no recent documents, nor any documents at all. I can't find the file on the phone to view it outside of my app.
Where do I have to save the file to make it findable outside of the app?
I think I've answered this myself. Viewing a PDF that an app created is just not a thing on iOS, as useful as that may be. You can of course do that on Android, which is far more useful. It appears that to view the PDF, you have to use iTunes on an iMac to download the file from the phone. Jumping through those Apple hoops, which I am slowly becoming accustomed to, I was able to view the file in the cordova.file.documentsDirectory location.

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

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.

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

ios native app allowed to save data from web?

We're building an iPad photo gallery with hundreds of images (almost 300mb in size). Having a web app will be a disadvantage because users will have to download the images every time (since Safari on ipad won't cache them I'm guessing?)
So if we built a native ios app instead, would it be possible to download newer images from the web and add it to the app in the future?
Thanks a ton for your help !
Each iPhone application has its own home directory containing Library and Documents folders, and a tmp directory for storing temporary files.
Take a look at section title: A Few Important Application Directories on The Application Runtime Environment.
I would save the your images to Application Home/Library/Caches folder.
Excerpt from Apple Docs:
Use this directory to write any application-specific support files that you want to persist between launches of the application or during application updates. Your application is generally responsible for adding and removing these files. It should also be able to re-create these files as needed because iTunes removes them during a full restoration of the device.
In iOS 2.2 and later, the contents of this directory are not backed up by iTunes.
http://iosdevelopertips.com/data-file-management/save-uiimage-object-as-a-png-or-jpeg-file.html
you could download it on first view, display at the uiimage, then save it off as above

Resources