Backup and Restore sqlite db during new version release - ios

I am working on an iPAD application. When a new version is released, I add the version number on the server side db and call it through a webservice and check with the build version of the app. If there is change in the version I am calling a URL to install the new version of the app. What will be the possible solution, not to lose my data from the iPAD app and once the new app is installed I use back the same sqlite db. FYI... I am not using any MDM, and installing the app through an URL. Let me know if I need to explain more in detail.

In the past, app version update usually reset the data to the bundle as packaged in the archive (ipa). The user data in the databases then become lost. (Note: this may have changed in IOS 7 because of the announced incremental update options but I have never been able to check it out).
My way around this is to provide a backup restore facility that creates a Plist in the /Document Folder. this allows the user to extract his data through iTunes File sharing, then restore it back if he or she wishes. If you have a server though, a better way would be to create folders for registered users and program the facility to back / restore from the server. Prompt the user to use the backup prior to any update, and prompt the user to restore data from the server (if available and the database is empty).

Related

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.

Getting to know if my app is updated from app store

I am going to publish a new version of my app on app store. I just want to know that if the app is being updated from the previous version or user has installed a fresh copy of the new version of my app. Based on this information i want to show some information to the updated users.
I was thinking of to keep a key in my NSUserDefaults of the previous_version but i haven't added any such key in the NSUserDefaults of my previous app version. So this key will be nil in both cases in my new version.
Is there a way i can get to know if the user has updated the app or installed a fresh copy of my app.
There is no direct way for it. Indirectly you can check it. If you are moving your editable data into Documents directory in your previous version then at the time of launching new application, you can check if the file is present in document directory. If you can find it, the application is opened after update and if file is not present then it has been opened because of a fresh installation.

Publish update-only distribution to Apple App Store

If I have an app that preloads a database when it first launches, is there a way to then in future publish an update only version for the app?
(IE excluding the preloaded db file so the update isn't bigger than necessary as an existing user wont ever overwrite their preloaded db - but at the same time being able to publish one WITH the preloaded db so that new downloaders will get a newer version of the db)
If there's an alternative way to approach it please let me know. Just to clarify, the app automatically updates the db with data when used - that's why I have no need to include the preload for every app distribution for users who have already downloaded.
I've looked on Google and can't find an answer - but maybe I'm just not using the right terms!
When you create an update to your application, your app will need to check if the user already have a database in the Document folder. If one doesn't exists, your updated app will copy the default database from the Application Bundle.
Also, if you add features to the app, new table or columns to your existing database schema it would be nice to use Core Data Model Versioning and Data Migration.
Excerpt from Apple Docs - Reducing Download Size for iOS App Updates:
Starting with iOS 6, the app store will automatically produce an update package for all new versions of apps submitted to the store.

Apple AppStore update process: how it affects the existing files

from what I understand an Apple app update would be installing a new standalone application instead of applying a patch to the existing one.
Does anyone know more details about this process? This applies to all the directories for the user? Any folders like Private Documents will be left untouched by the update. How about the other folders like Documents, etc.. I am hoping to find a document describing the behaviour, but could not find one so far on the web.
By update I mean: let's say the user has version 1.2 ... and then pulls data from the application server when available. And then 1.3 comes online to the App Store.. the user updates to 1.3.
As explained here: iOS App Programming Guide, all you need to know about updates is that:
Files Saved During App Updates
When a user downloads an app update,
iTunes installs the update in a new app directory. It then moves the
user’s data files from the old installation over to the new app
directory before deleting the old installation. Files in the following
directories are guaranteed to be preserved during the update process:
Application_Home/Documents
Application_Home/Library
Although files
in other user directories may also be moved over, you should not rely
on them being present after an update.

IOS Enterprise Distribution update keep user data?

I'm making an iPad app which will be distributed from my own web server using Enterprise Distribution Program.
The app itself checks for a newer version on the server and calls itms-services in IOS to update itself. This works perfect.
The app bundle contains a directory with resources like images and movies.
Apple claims that updates will keep the users data if the bundle-identifier is the same.
From: http://help.apple.com/iosdeployment-apps/mac/1.1/#app43ad802c
If you want users to keep the app’s data stored on their device, make sure the new version uses the same bundle-identifier as the one it’s replacing, and tell users not to delete their old version before installing the new one. The new version will replace the old one and keep data stored on the device, if the bundle-identifiers match.
When running the app from Xcode directly to my connected iPad, I can remove the folder with my resources, run the app again, and the folder remains in the bundle on my iPad.
This behavior is what i look for. I'm planning on adding more folders with new resources with new updates. Since the resources are quite heavy, I don't want users to have to download bigger and bigger archives. I want to add just the new stuff.
The problem arises when I make a new archive without the folder and update the app from my web server as users would. Then the folder seems to be deleted.
Any experience with this?
The bundle that you install is always overwritten by the new bundle that you install. The user data referred to in the documentation is the data stored in the Documents and Library folders of the file system. If you wish to be sure that the old bundle files will always be available, you can copy them from the bundle to the Library/Caches folder of the application.
One thing worth mentioning is that the way to ensure that the ad hoc installation overwrites the current bundle is to make sure that you change the bundle version.
hope this helped :)

Resources