Do app updates overwrite the app's home directory? - ios

I use the NSHomeDirectory() function to get the app's home folder, and write to the Documents directory within that. I'm curious, though, what happens when the user downloads an update for the app from the App Store? Will it all be deleted? When I delete the app on the device, then reinstall it, it's wiped out. So, I'm curious to know what will happen with an update. I can't find this in the documentation at all.

Stuff inside ~/Documents/ and the user preferences are preserved during update.
See the iOS File System Programming Guide.

Related

Switching to File Sharing enabled false

I have an app already released to the store and I do not want to have my Documents folder visible to the end user in iTunes. Is there any potential issues from switching the Bool from true in the app store version to false for an update?
All existing apps won't see have any issues? I tried googling and couldn't see any mention of this causing a problem but just wondering if there's anything I need to worry about
I've made the experience that that's not a problem. Users of the old version still see the Documents folder of the app in iTunes, while users who update do not see the folder anymore.
Also, nothing changes to the files in the Documents folder. Files that are located there remain there, no matter if they were created by the app or if they were copied by the user via iTunes.

Fetching previous saved database file after reinstalling the app

I am new to ios development so please pardon if I am asking a silly question.
I need to check if my sql file from the previous installation of the same app exists in the device directory already. If yes, then I need to fetch that file instead of making the new one. But the bundle folder of the app changes after reinstalling the app. So I cant guess the name of the previously installed app bundle folder. I tried to save it elsewhere on the device, but it isn't allowing me. Please suggest me the solution.
What you're asking for isn't possible. If an app is removed, all its files are deleted as well. In iOS, there is no app-neutral place to store files. When an app is merely updated, the update happens "in place" from the perspective of the app, and all previous files are available.
If you want files to survive a delete-reinstall cycle, you'll have to use a cloud service, such as iCloud, Dropbox or Google Drive.
once app is deleted. Application bundle and document directory and all files (including SQLite file)are deleted. u have to fetch all data from API.
In iOS each application is a Sandbox. This Sandbox consists of Application bundle and Mutable part where you store your database and other files which are mutated during the life span of an application.
When you delete the application, entire Sandbox is removed. The only thing which does not get remove is the data which you have stored in keychain.
When you update the application, only application bundle gets updated and Mutable part remain un-touched. So while re-installing the application when it is already present (technically updating the existing application on the device), you can find the same file from the same location.
You can do one thing you can take daily backup of that file on remote server and when you reinstall app check that file exist on server if exists than download else create new.

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 - letting another app edit and save files my app created, in the same folder where the file was opened from

I would like to know if it is possible to let another iOS app open a file my app has created and then the other app edits and saves it just in the original location where my app had saved it at creation time. Or, instead, are files opened with the NSUrl in UIApplicationLaunchOptionsURLKey just read-only so they just can be saved in the other app sandbox?
You can't edit other apps sandbox, it's private to your own app (except for the Documents folder, that a user can access from iTunes).
You also don't have access to the file system of the phone.
Welcome to iOS :)
The best way to achieve this is a custom URL scheme. The other option would be iCloud, but I think the URL scheme is the way to go here.
Edit I see the link doesn't work correctly, not sure why, just scroll the page down to the Communicating with Other Apps paragraph.

Is there a way to not erase the documents directory when uninstalling the app?

I'm developing an AIR app for iPad, and I found that when I uninstall the app, the documents directory data gets erased, is there a way to keep this data even when I delete the app or this behavior is regulated by iOS and there is nothing I can do about it?.
Thanks.
No you cant
From The iOS Environment
For security reasons, iOS places each app (including its preferences and data) in a sandbox at install time. A sandbox is a set of fine-grained controls that limit the app’s access to files, preferences, network resources, hardware, and so on. As part of the sandboxing process, the system installs each app in its own sandbox directory, which acts as the home for the app and its data.
So you delete the application all the content regarding that particular app gets deleted.
as soon app get uninstalled the document directory folder also get deleted with that. Although you will not able to access that folder from other apps so there is no need to keep that.

Resources