Core data / Read only / Swift 3 - ios

Working with core data, I have build the following files:
MyApp_DB.sqlite, MyApp_DB.sqlite-shm, MyApp_DB.sqlite-wal.
Those files will be included in the app bundle when shipping and they are rather big.
Once my app is published I want the database to be read only. Therefore there is no need to copy the files above outside of the bundle.
Here is my question, how should I configure core data in my app so that I have access to my database?
Things have changed with Swift 3, so the code I had working before does not function anymore.
I want my app to work with iOS 9 and iOS 10.

Related

Core-Data with a preloaded database

Using Xcode (Version 8.3.3) I created a sample app with the template for Single View Application and clicking Use Core Data.
At this point my app is running and I have a database containing data that I do not want to rebuild each time the app is started.
In other words I have the files:
MyApp.sqlite, MyApp.sqlite-shm and MyApp.sqlite-wal
I copied those files to the MyApp project folder.
Now here is my question:
How do I need to change the code so that the app will use the data in the database next time it is started?
Note: the only code I have related to the question is no more than the one automatically generated by Xcode.

Replace core data model in new version of app without having previous source code

Hi I struck at core data migration issue. I have developed a app which is new version of an existing app in Appstore. But i don't have source code of previous version and don't know exactly that whether core data was used in old version or not. So how to update my app (which has core data) to Appstore without any crashes. Any quick solution please?
Since you mention in a comment that you want to ignore the old data, you don't need to do any kind of migration. Model migration is about updating existing data to work with a newer data model. The only danger would be if the old app used Core Data and your new app attempts to use a persistent store file with the same file name. Then your app would attempt to load the old data, since it would find that file with the correct name.
The easiest way to test this is:
Install the existing app (from the app store)
Use this app until you're sure it's saving some data
Install the new version from Xcode. Since it's an upgrade, it will overwrite the app store copy.
By then you'll know exactly what happens when upgrading. If you get a Core Data related crash, change your Core Data setup to use a different filename. Then delete the app from your iOS device and repeat the test from above.

SQLCipher data takes more space in memory?

I am working with an sqlite database in my android app. I read data from url and write it into database using android.database.sqlite.SQLiteStatement. This way I get about 1.5 MB app data. Recently, I switched to net.sqlcipher.database.SQLiteStatement, now I get about 8.5 MB app data, which is approx. 5 times bigger. Why is it so? is there a way to decrease data size while using sqlcipher still?
The additional application data size is due to the inclusion of the ICU data file. For more information, see the Location Dependencies section of the SQLCipher for Android documentation:
SQLCipher for Android depends on localization data from the ICU
project. SQLCipher for Android will attempt to use a system provided
ICU localization data file called icudt46l.dat located in the
/system/usr/icu directory if available. If that is not found,
SQLCipher for Android will attempt to unzip the icudt46l.zip file
located within the applications asset directory. It is recommended
that the icudt46.zip file be included with your application for best
platform compatibility. If you need to adjust the size of the
localization data for your application, a ICU data library customizer
is available here.

iOS 6 local storage file appears twice

I have an app that uses local storage (using sencha 'Ext.data.proxy.LocalStorage') to view some content offline. I was rejected by itunes for violating the iOS Data Storage Guidelines.
I thought it might be related to the localStorage being inside the /Documents folder in iOS before iOS 5.1. To confirm that in newer versions the document folder is empty I checked, but I still found a .file__0.localstorage.
The strange think is that the same file (but without the leading dot) also exists in the library/caches folder, where it should be.
Both have the same content.
Does anyone know how this can happen? I already asked in the Sencha Support but it does not seem to be related to the Sencha framework.
Note: I am not using PhoneGap, only Sencha.
Making a very small Hello World Application with Sencha that writes to local storage I could reproduce this behavior. It seems like on application exit, it will write a copy of the localstorage file to the /Documents folder.
This seemed suspicious to me and it reminded me of the PhoneGap patch for iOS 5.1 that backs up the localStorage file also.
With iOS 5.1 Apple started to put the localStorage file in the Library/Caches folder which broke many applications because the data was no longer reliable stored. So PhoneGap and others started to implement Workarrounds that backup the localStorage file to the documents folder and automatically restore it if needed.
Trying to find proof that Sencha does something similar, I opened up the resulting .app package and found a stbuild_template file that contains the native wrapper code. It is of course compiled, but searching for the string "localStorage" results in some interesting results like:
restoreLocalStorage
preserveLocalStorage
Could not remove source file while backing up localstorage Could not copy localstorage backup . Caches WebKit/LocalStorage .file__0.localstorage file__0.localstorage
SNLocalStoreageFix
Also I found a lot of references to NimbleKit which seems to be used internally for the packaging.
This thread also hints at a solution for the iOS 5.1 local storage problem in Sencha Touch 2.1 which is what the OP is using: http://www.sencha.com/forum/showthread.php?194674-Localstorage-and-native-iOS-5.1-apps&s=04149e771f9c4eea15cb6f6d97069ff6
All this is evidence for me that Sencha implemented a workarround for iOS 5.1 which will put the localStorage in the /Documents folder. Since you only use the localStorage file for caching, Apple rejected you because you store non-user data in /Documents.
I think using PhoneGap there is an option to disable this backup. So you might want to consider using this or ask Sencha if they have a similar option to disable it.

iOS file downloading library

In my iOS app I use HTML5 files as game levels. New levels will be added in the future, so I need to create a smart solution that will sync files on device with files on the server each time a new file is added or an existing file is updated on the server. Ideally it should work like SVN update. Is there any existing library that solves this problem?
you can use a web service, you will have to implement it on your server [with your favorite language-framework ie: php-codeigniter, python-django, ruby-rails]
I recommend using JSON for simplicity.
on your iOS side, with iOS 5 you can use NSJSONSerialization

Resources