How to empty SQLite DB for iOS distribution/ Generic iOS build - ios

I just submitted an app to the App store and it is now available. Unfortunately I realized that my development test data was included in the SQLite database! How do I go about emptying my database for the distribution, in other words removing all rows from tables? I know how to do this for a simulation (Reset content and settings), but since the deployed version just uses the Generic iOS build that does not run in the simulator, I am not sure how to clear the database.

Figured this out myself. You have to find the location of the sql file in your project.
Find the .sql file in your project.
Go to File-> Show in Finder
Then go to that location using Terminal and use sqlite3 to set up your DB as you want it.

Related

Data is not getting from sqlite DB in device but it is working in iOS Simulator

In my app I want to display data from sqlite database on UIPicker View.It is working fine in ios simulator but data is not fetched when using iphone device.I m not getting the issue.How it can be solved???
Are you sure there is sqlite file available at path? sqlite3_open() will create the file if its not exists. Please check wheather you have created sqlite file in bundle, if yes you cannot do that. The file actually has to already exist and be copied into the bundle as a resource at build time, then used as a template to copy to a writeable area like the documents folder. The best way, if you intend to create a writeable database, would be to get the path to the Documents directory and use that. You can and should do that unconditionally, without regard to whether you are running on the Simulator or not. Indeed, I would suggest not creating any more differences between Simulator behavior and device behavior than you face anyway.

How to preload data into an iOS app using sqlite files

Prior to the new Xcode 5 build, I was able to preload data into my core data powered app by referencing the file from the project. However, ever since I upgraded my XCode, my json data is now being saved into 3 files:
an empty .sqlite file
a .sqlite-wal file
a .sqlite-shm file.
How do I do import this data into my app?
In the past all I had to do was copy the sqlite file and I was done. Now, I have no idea what file I'm supposed to copy.
I can confirm "compacting" the database using the FIREFOX add-on provided by #Lukasz Kowalski herein is confirmed with 10.9.1 / Xcode 5 / iOS 7. To clarify procedure...
download Firefox, then get his SQLite Manager add-on.
Copy enclosing StoreContent folder with PersistentStore, PersistentStore-wal and PersistentStore-shm files to desktop for re-combination into single pre-iOS7 UIManagedDocument database that functions as before. where to find:
~/Library/ApplicationSupport/iPhoneSimulator/7.xx/Applications/gobble-d-gook/APPNAME/Documents/APPNAMEDatabase/StoreContent/{your database files}
Launch Firefox, open window, from menu Tools > Sqlite Manager
Use SQLite Manager to open database: desktop > StoreContent > PersistentStore
Select from Menu > Compact Database option.
Select from Menu > Close Database
done! they are combined.
I found out from apple's developer site that in oder to get core data to behave in the old way (pre-iOS 7), and generate just the sqlite file, I had to add this to the persistentStore addStore method, under the options parameter.
#{ NSSQLitePragmasOption : #{ #"journal_mode" : #"DELETE" } }
I hope this helps anyone else who encounters this problem.
Cheers
Try just the sqlite file. See if it works, add the other two one by one.
You could also save the JSON in a txt file and on load parse it into Core Data. Depending on how much data you have, you should do this in batches with the first batch being just large enough to populate the first view and then continue parsing the rest. All in a background queue off course.
Not as easy as it was before, but this is a solution. Maybe someone else has a better solution?
I have found solution to create 1 .sqlite file when you have 3 files: .sqlite, .sqlite-wal and .sqlite-shm. To do that you should use „SQLite Manager” addon for Firefox (https://addons.mozilla.org/pl/firefox/addon/sqlite-manager/?src=userprofile):
install and run addon in Firefox
open your coredata .sqlite from directory of your app in iPhone Simulator
use Compact Database which will produce 1 .sqlite file :)
now you can use old method (prior to XCode 5) to include .sqlite into your application

viewing coredata with sqlite browser in xcode 5

Since upgrading to XCode 5, I am unable to view data in the sqlite file in my Applications Folder. The folder structure has changed somewhat but I can still find the correct App but when I open the sqlite file with the sqlite browser there does not appear to be any data in CoreData.
Any ideas?
I suggest you to use CoreDataPro app for viewing your CoreData storage.
My fork has minor improvement - alphabetical ordering of Simulator managed object models.
In iOS 7 SQLite's Write-Ahead Logging is turned on by default. In this mode data is split into three files (.sqlite, .sqlite-shm, .sqlite-wal). I've seen that some SQLite viewers ignore .sqlite-shm and .sqlite-wal files, thus not showing proper data.
I'm using SQLite Manager plugin in Firefox, it works pretty decent.
You can get the plugin here https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
After you install the plugin you will see 'SQLite Manager' (with a database icon in blue color) item in Tools menu.

iOS app behaviour after installing new version from app store

I have an iOS app installed in iPhone from app store, now if I have an updated version 1.1 for the same app at app store and I'm getting some sort of informative alert from the older version 1.0 (New version is available...).
If I click on alertview's ok button, it redirects me to the new app link in browser. I download my new version then.
Please provide answers of following questions :
Will it replace old version?
Will it replace sqlite and image folder on the document path? (Both version is having same named sqlite file, say abc.sqlite1.0 and same folder name, say imagesToBeCopied)
Will it append the sqlite entitie rows with new rows for same entity?
How can I install version 1.0 again from app store? Is it possible to get it anyhow?
Please provide your valuable answers on it, which can help me out to reach to some solution.
Thanks.
1.Will it replace old version?
Yes, the app bundle will be replaced by the new one
2.Will it replace sqlite and image folder on the document path? (Both version is having same named sqlite file, say abc.sqlite1.0 and same folder name, say imagesToBeCopied)
No, the documents directory is not affected by the update process. If you have procedures in your code that update the documents directory, they will still run, but without any changes it would be no different to a normal launch of your app - e.g. if you check for and copy if needed, something from the bundle to the documents directory, this will only happen if the target file doesn't already exist.
3.Will it append the sqlite entitie rows with new rows for same entity?
This is not related to the update process. If you want to modify the data as part of the update, you will write this specifically in first launch code for your new version.
4.How can I install version 1.0 again from app store? Is it possible to get it anyhow?
No, the updated version replaces the old one on the app store.
To the best of my knowledge...
Yes, the new version of the app will replace the old version.
Yes it will replace your sqlite file, assuming your paths did not change across versions. If you want to handle this sort of case it is your responsibility to include logic in the newer version of the app to check for the existence of the sqlite file and overwrite or modify it accordingly.
No, all modifications to the sqlite file need to be done manually by the new version (see #2).
As of now, not possible to do this through the app store. Only one version of any app can be placed for "sale" at a time. You would have to do this through other means (testflightapp.com for instance [for adhocs for devs]).

core data testing a migration mapping model

I was wondering what some people's opinions are about the best way to test a mapping model? I'm currently working on an app to an upgrade of an app in the app store and want to test the mapping model hard before submitting.
Found this one accidentally, to test a migration, before starting simulator, just... copy a file. You need to overwrite your app database with an older version (all CoreData data and metadata is in)
The Simulator install your app there :
"/Users/<username>/Library/Application Support/iPhone Simulator/<iOS Version>/Applications/<Some UUID>/"
The CoreData Database is probably there (depends on what you do) :
"/Users/<username>/Library/Application Support/iPhone Simulator/<iOS Version>/Applications/<Some UUID>/Documents/whatever.sqlite3"
You can quickly open this folder from terminal using :
open "`find ~/Library/Application\ Support/iPhone\ Simulator/<iOS Version> -name '<your.app>'`/../Documents"`
Then just keep a backup before migration, and copy it over simulator one before starting your app.
I have been doing exactly this same thing.
I use iPhone Configuration Utility to install the 1.0 version of our app (repeatedly). After that, I simply run the current version of the app (1.0.1) in the debugger in Xcode. Works just fine. HTH

Resources