How to delete application data on install and reinstall - blackberry

How to delete application data on install/reinstall application, so I can have a clean working environment on every reinstall ?
I mean how to detect that this application has been reinstalled so I can clean the whole persistent store.
Thanks.

In the 5.0 APIs there is a new class called CodeModuleListener which you could use to monitor when your modules are being uninstalled. Prior to 5.0 though, there are no hooks. However, here are a few ideas to think about and/or try:
Use the CodeModuleManager methods getModuleDownloadTimestamp() or getModuleTimestamp() (not sure which one would give the proper information) to look up the "install time" of the module, then store it in persistence. Then each time the app is started, read the value from the module again and compare it to the persisted value. If the module value is newer, then the app was reinstalled.
If you store a non-native class in the Persistent Store (i.e. a subclass of Hashtable), it will be removed from the persistent store when you uninstall the app (since without the app, the class is meaningless). So all you need to do is create a subclass of Hashtable and store that in your persistent store (with your actual data as keys), and it will be automatically removed from the store when the user uninstalls the app.

Maybe I'm misunderstanding, but shouldn't your uninstaller just delete the persistent store? Some uninstallers have a checkbox option that lets the user control whether or not their data is uninstalled as well, but it's definitely the uninstaller's job to get rid of it if necessary

Related

Crashes from Updated/Released Production Core Data Models

Background/issue: I have a Core Data app in production and I just sent out an update where I added a couple of attributes in an existing entity without making a new model version (I didn't know this was a step). This is causing my user's apps to crash. The crash only happens when they first open the app after updating then it seems to work fine after the initial crash.
How I think it can be fixed: I'm thinking that I should go to a previous commit > copy the old data model > go back to master > delete the updated data model > drag and drop the copy into Xcode > then go to Editor to "Add Model Version". After add the new attributes I need I'm scared to do this and submit it to the App Store as it may cause more problems for people who already updated their app.
Ask: Is there a way I can revert my changes to the old data model version then make a new one from that? Without affecting my current users who already upgraded to the database version with errors?
I paused the phased release of this update to stop having users get crashes so if anyone knows how to fix this please help!

How to deploy App to Apple Store with repopulated database(SQLite)?

I am developing my mobile app using react-native, and database goes with it, I am using SQLite storage.
The way I work with it:
create it using python script and copy it to path where virtual device takes.
Obviously I need somehow to bundle it within my app in order to run on real device?
I have 2 options in mind:
1. Keep state of app using AsyncStorage, where to store isDBCreated
variable, so we creat DB from json file that is shipped with the app
only once and then use it on consequent runs
2. Somehow bundle created DB
With 1 - I am confident and know how to do it
With 2 - don't know ( I have followed official documentation in order to bundle it on IOS, but without luck)
From your experience, what is the best way to bundle database?

When can "This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation." Error Occurs

"nspersistentstorecoordinator has no persistent stores. it cannot
perform a save operation background thread".
Can saving manageContext on background thread cause this issue ?
Sorry if this is already asked. I would like to know the probable reason for its occurrence ?
Apparently you have created a memory-based persistent store coordinator, instead of one that use an SQLite database (the usual case) or XML for storage. Since there is no file holding the database, you can't save anything.
Check the code where the persistent store coordinator is created.
If you used the default code from Apple verbatim then you are likely getting an error when creating the persistent store coordinator, but ignoring the error. Apple's boilerplate code checks for the error and has a comment in the if check that just says "/Error for store creation should be handled in here/". You should at least log a message in there to see if you're hitting that code path. If so, that's your issue. :)
NOTE: You can hit this problem when switching from new code (with a core data upgrade) to older code (e.g., in a branch) that doesn't have that upgrade. If you don't run clean in xcode, the compiled model file from the newer build can get put into the older build and cause you heartache.

Can you know if the user installs your app for the first time or if he made an update?

Is is possible to know if the user made an update or a fresh install considering that I didn't though of it before this version (so my previous version put no user default or keychain flag for me to use in my current version for checking)?
I don't believe resource files are deleted on install. If you have an image in your resource bundle, or perhaps you could even use the app icon, you could change the name of the image and then check for the existence of an image in the resource bundle with the old name.
Of course, I would test this first, but I think it will work

iOS Core data migration to another machine

I received the source for an application from a guy to make a few changes in the app. The data model version was, say, App3. I had to add about 3-4 more data model versions in the process. So the active model version when I sent him was App7
I built the project (it was running properly on my mac)
I sent him the zip and when he ran, he got the error "Can't find model for source store"
I had him create the latest data model again, based on the data model App3 and make it the same as App7 and set it as the current version.
He still has the error and I can't figure out why? Are the intermediate data model version causing issues? Is it required to delete the sqlite file in the application support->iphone simulator folder? I am all over the place with this. Please help!
You need to have both model files and have some sort of versioning in place. The new model that you made will no longer work with his data file unless you specify to Core Data that you want it to update the data.
Versioning isn't that easy, but if your changes are small enough, you might be able to get away with automatic versioning. Read the guide and see:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html
In my understanding, it will. But really that is not the thing to do if ultimately the versioning is going to happen on existing live apps too.
For the light-weight migration to work, you need to send him all the intermediate versions of the model as well since the migration takes place stage by stage through all versions.
And you have to make sure that you have made no modification (even accidentally) to the base version App3.

Resources