Core Data persistence after uninstall a application - ios

Before I delete an application, I want to be asked for:
Do you want to delete also the application data?
as we know it from other applications. I searched for it but I don't found any clue. It is related to CoreData.
Do you know how I can achieve this?
Thanks for any help!

When your application is deleted, its associated data will be as well.
You can instead offer to persist it to an external resource (Firebase, Azure, etc.). Then, it can be available at a later date. However, you must do this prior to deletion, as there is no way for your app to know it is being deleted & respond to it.

Related

Best Practice to store local data in ios framework project

I am working on a custom framework which will be used by developers. I am saving some data locally inside my framework for that I am thinking to use UserDefaults but I want to know:
Is it the best method to do so?
If the app UserDefaults are cleared then will it clear my frameworks data also?
I want to know how can I store local data in ios framework. What is the best solution for this?
I am confused about it can anyone help?
It depends on the data you want to store.
If your goal is to keep some settings for your framework (e.g. whether some features should be enabled or not) then UserDefaults will do.
If you want to store user's data (or anything you can get from the server) then you should probably consider using CoreData, which is a native iOS/macOS/tvOS persistent storage.
You can also use Realm database, but it's not a good idea to use it in frameworks, since it will be added to any application which will use your framework (and the developers probably won't be happy about this).
Regarding you questions:
It depends, see above
Yes
Userdefaults is great but at times it turns into a mess if you have alot of information that needs to be stored. Specially the fact that you would need to manage a key/value relationship throughout the app and usually the keys end up being more than 10 plus ..
Just a suggestion but why not use CoreData to manage models and store data in sqlite db on device. When the framework is loaded you can check if the data exists if not then fetch it.
I would suggest using the functionality provided by apple natively rather than going for 3rd party solutions like Realm, with 3rd party you would need to upgrade to their latest version in order to make things work fine.
Please read these to clear any confusion.
https://cocoacasts.com/what-is-the-difference-between-core-data-and-sqlite/
Tutorial on using Coredata:
https://www.raywenderlich.com/7569-getting-started-with-core-data-tutorial

Is there any way to migrate data from CloudKit?

I'd like to build a simple iOS only app that's going to be social. I don't yet have a way to monetize this app, so I'd like to keep this project as cheap as possible. Since it's iOS only, I figured I would use CloudKit because of its very generous free tier. However, if I ever decided to make this a cross platform app, would I be able to migrate my user data somewhere else?
I think you can use CloudKit with Android because of the CloudKit JS implementation. The real problem is, that I think that also the android user needs an iCloud Account do something with that.
So maybe the better way is to use google firebase.
https://firebase.google.com
As of December 2019, there is no simple way to migrate data from CloudKit. The data stored in each user's private data base is not accessible by the developer.
There is always the option to do this inside of the app for each individual user. If the data is not too large and complicated it should be easily done.
But make sure to inform the user and give them a choice to move or don't move the data. Let both services run for some time parallel before removing the cloudkit option for old users completely. Obviously moving data using the app can cause certain issues if the move doesn't go as planned.

If I make a database on Realm, will it be accessible to my user without internet access?

I'm trying to build my first Swift app and I think Realm may be a good option for my database. This might be a totally stupid question, but will my users be able to access the data on my database without an internet connection? I'm fairly certain that the answer is yes, but I just want to make sure.
As a side note, I want the data to be stored on the users phone (not a server or anything like that)
Thanks for the help
Yep! Realm is a completely offline, local database solution. There's no online component, but if you do decide to, you can sync data from Realm online using third party cloud services like Parse (Or just literally copying the database file to Dropbox).
By default, all data saved with Realm is stored in a file called 'default.realm' in the Documents directory of your app, but you can easily explicitly set where you want the data to be saved.

How to get User Data from the App?

Is there a way to get data from the user while they use my app on their device (iPhone/iPad). For example, if the app fills a dictionary during the runtime about which avatar is used most of the time and which avatar not, is there a way to transfer that dictionary to me? Do I need a server?
This is my first time thinking about data transfers over the internet. I don't have any idea or any experience on how to do that. Somehow I feel it is impossible for some security reasons. I found the NSURLConnection class, but this seems to be only one way to move data from a server to the app.
Thanks.
Not sure if I fully understand the question, but I am assuming you would like to get information about how the user is using your application?
This is definitely possible; and yes, you will need a server to send, retrieve or store the information that you require, or else there is no way to get the data from the application to you! You will need to learn how server side and client side web scripting works (if you do not know already) as this is how the application will communicate with your server.
Depending on the kind of information you are trying to retrieve, there may be security issues and Apple may not accept your application. However, if your data is specific to your application features, there should be no issue of this kind.
HTH

How do I perform Core Data Migration to an existing app, if all I'm changing is the SQL Db's content?

I've checked a lot of sites and answers and I can't find any solutions specific to my problem.
I don't need to change the schema for my Core data model, all I need is to modify (add some) content to the current backing SQL Database.
Any direction on this will be welcome. Thanks.
PS: I tried Apple docs and they were about as useful to me as sunshine on Mecury.
Also go easy please, I'm a beginner.
Thanks.
UPDATE;
To shed more light on my issue, my app works as thus. I have preloaded static information on the app that can't be changed by the user, each day has new content. Every month, I push an update with entirely new content specific to that month. However, when my app entered production, upon the update I pushed for this month, my users were complaining that they couldn't access the month's data. This led to me spamming them with Push notifications to have them delete the app and do a fresh install to access the new data.
How can I fix this issue? my schema stays the same, only the data changes.
If I understand correctly you want to pre-fill a Core Data database ?
If you don't care about pre-existing data on existing app, you can make an iPhone or Mac app with the same model, and let it generate the database, like explain here (Any way to pre populate core data?) it's also the way recommended in a really great book if you want to learn more about Core Data (http://pragprog.com/book/mzcd2/core-data).
Do not ever make SQL request directly, Core Data work in his own magic way.
Don't work on the SQLite-Database directly. Change all your Data through NSManagedObjectContext! To find a good strategy look up examples from Batch-Importing.
Update: You could actually have two PersistentStores (one with just static data (readonly) and the other one with user-generated data). You could interchange the readonly which you prefilled with a commandline util and downloaded from a server. You cannot have direct relationships between those two store though.
I would say that it depends on the amount of data in this prefilled store wether you should go this way or just use a plist and reference some string constants in your user data store. Try to do it with a plist as this is the simpler approach.

Resources