How to check persistent storage? - ios

I think I'm being completely stupid but....
I want to check if some of the data has been stored correctly in persistent storage. In the simulator (I don't have an iPhone), I'm currently killing the app, then Xcode throws me an error (rightly so) and I can't reopen the app afterwards. Is there another way of checking the persistent storage?
Thanks a lot in advance

If you are using a real device you can download the contents of the app's folder using Xcode:
Window --> Devices
Select your Device
Select your app
Click the gear icon --> Download Container
The downloaded container will have all the contents stored on the filesystem in your apps folder.
If you are using the simulator you can use a tool like SimPholders to find the app folder on your mac.
If you saved something into UserDefaults you have to look for a file named <bundleIdentifier>.plist. That file will contain all the UserDefaults for your app.

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 access Xcode database from iPhone app

This is my first iPhone app. I'm using Xcode 7.3.
In the app I used this tutorial to create an sql database using the app (when the user gives permission by pressing a button, it creates the .db file).
Now I would like to know how I can download the database from the app.
Here is why:
The app will be downloaded on someone's device (not via the app store). It is supposed to collect data from a wearable device and store it in the database.
However I don't know how to access that data later on when I have the user's phone. Apparently the db lives in
/var/mobile/Containers/Data/Application/###/Documents
I read that one method is "jailbreaking." But I have never done that and this is not my phone I'm dealing with, it's a client's, so I don't feel comfortable hacking it. Is there another way? Possibly through the terminal (this is how I did it with the android app, using adb)?
Or is there another way I can go about saving the database so that it is accessible/retrievable?
The first answer is correct but incomplete :
Once you have download the Container, the extension is .xcappdata, so you need to right-click on it and select show the package.
Then browse into /library/Application support/ to find your database in .sqlite
You can try to connect the device to your Mac, then in XCode, go to Window, Devices, select your device and app bundle and click "Download Container...".
To see the database, you could use SQLite.

Yosemite, iOS 8 and iCloud drive: syncing mobile to desktop?

I have a couple of iOS 8 apps that make use of the new iCloud Drive service and the native API for copying files to the app's personal iCloud file directory. Using two separate devices, I can upload files on one device, and download it on the other: so far so good. Now, having upgraded my macs to OS X.10 Yosemite, I have the iCloud Drive folder, but it only shows the files from the one applicable Apple product that I ever use (Keynote):
The files that are happily syncing between mobile devices are nowhere to be seen; I'm pretty sure that the documentation implies that they're supposed to be there, and that the distinction between mobile & desktop folders has been taken away. If I hunt around in ~/Library/Mobile\ Devices, I can find them, so they are updating behind the scenes. Or perhaps that update happened when the computer was still running OS X.9 Mavericks.
Anybody know what I'm missing?
On Yosemite it seems Finder is treating iCloud as a special folder, so it doesn't show the hidden files and folders. If you use Terminal to examine ~/Library/Mobile Documents/ it all seems to be there.
Trying to put the full pathname into Finder just dumps you back at the 'official' iCloud view, so it looks like Terminal is required in order to browse these on OS X.
What fixed it for me was going to System Preferences, iCloud, unchecking iCloud Drive, restarting the computer, and then repeating but this time checking iCloud Drive.
I discovered an easy way to view the original Mobile Documents folder without the view switching to the new iCloud Drive view.
Access your hidden Library folder within your User folder. (for example, click the Go menu in Finder while holding down the Option key)
Then select the Mobile Documents folder and create an alias to it (by right clicking)
Now, double-click to open the alias. Presto. This opens the actual Mobile Documents folder.
You will notice that some of the folders names have changed. You will note the iCloud Drive folder is also present.
It may be helpful to use the terminal or another utility to unhide the hidden files in Finder.

Debugging & accessing NSDocumentsDirectory in real device

I have my apps using NSDocumentsDirectory for saving the downloads & offline data on device. From debugging point of view, I was debugging as usual on simulator & was trying to access the path for these downloads & I was able to do that. I have my doubts as :
I am not able to access the location /var/mobile/Applications/SOME-HEX-CODED-PATH/Documents/ via terminal that was shown in the NSDocumentsDirectory paths during debugging on device. Whereas in iOS Simulator I am able to open , read/ write at that location.
I am not able to browse through the /var/mobile directory as it is not listed in the finder, not even as hidden directory.
Is that directory is mounted on runtime ?
Please clarify.
I am not sure to fully understand your question. You want to access, from your laptop, the filesystem of your device?
You are not supposed to do that on a regular device at least. If you want to browse your documents directory do it through the organiser (Window/Organiser) and then "devices" tab and select your device and your app. You will be able to see your sandboxed filesystem in the bottom part and downloaded its content.

Copy file to/from NSDocumentDirectory during dev

I'm playing with NSDocumentDirectory and saving files on my iPhone. I have created a dictionary and saved it successfully to NSDocumentDirectory and I can re-load it upon re-launch of my app. However, during development I would like to actually browse and copy files to and from NSDocumentDirectory. Is there a way via X-Code or Finder or iTunes to see the contents of my app's NSDocumentDirectory?
The real goal here to move a file generated on my iPhone to my iPad, but starting with copying back and forth from Mac to device would be great!
Any advice is much appreciated.
You can transfer files to / from app's Document directory through the File sharing feature in iTunes. To do so, you have to set UIFileSharingEnabled property to YES in your app-info.plist. See this question if you have problems setting it up.
Download iFunBox. It will allow you to access the IOS file system.
The latest version is here.
IPhoneExplorer is available for Mac and Windows.

Resources