I have developed a server based app for iPhone. But according to client requirements and to avoid overloading on server side, i am required to store data on local end. It is all text and typically 2-4 MB in size.
For this i'm using NSUserDefaults instead of sqlite or CoreData.
The app has been tested successfully for around 2-3 months during it's development as well as post development testing and never shown any type of inconsistency in data storage, updation or deletion on any sort of iphone device from iphone 3G - iphone 4S.
Now there is an incosistency issue in the live app, when user leave the app idle on a screen for around 15-20 minutes and doesn't press home button means app is not in the background.
In this case, data seems to be lost.
But as soon as refresh app, in that case data appears again & app starts functioning normal again.
Here lies the main problem that when i'm refreshing, i'm doing nothing but only fetching fresh data from the server it can be simply one to five records or nothing at all.
Then app is refreshed, all of the records are shown & it functions normally.
I have been trying to spot the issue for around 3 days, and it's not happening on my device (iPhone 4S). As far as i can think, it seems to be problem with the old devices.
Previously in testing, none of this happened on old or new devices.
My questions are -
a) Is this an incosistency in my coding?
b) Are NSUserDefaults not trustworthy for database management for live apps?
c) Is it a device version specific problem related to NSUserDefaults?
Anybody faced/facing the problem with NSUserDefaults??
Please suggest me something i can do for this or tell me i have to do all the database work again for the next version using sqlite or CoreData.
Anyhow this is critically important and needs to be fixed.
Any help is appreciated in advance.
As my suggestion for you please introduce the Sqlite database integration because of the when the short size of the data store and of cause it's good rather then the Sqlite but it's not working into large number of the data that time must use the Sqlite or coredata.
so i suggest to use the Sqlite data and coredata.
Related
We have finished writing an iPhone App that uses coredata.
In further versions we plan to add an iPad App that is able to display the data collected by the iPhone App (and of corse modify, use it) to give more interaction possibilities to the user.
My question is: Is it possible to move existing coredata (of already installed apps on iphones) to the cloud and read that data out with an iPad application?
If yes: can you point me in the right direction of where to start?
If no: is there another alternative to access coredata created with an iPhone App with an iPad app?
When using Core Data's built in iCloud support it doesn't matter what kind of device you're on, only that the Core Data stack is initialized the same way. Any iOS device or Mac can use the same iCloud store, and data created on one can be read on another.
One crucial detail though: If you already have a data store and you add iCloud support, those pre-existing records do not automatically get migrated to the cloud. iCloud works based on transaction logs, and transaction logs are only created when you save changes. Existing data that doesn't immediately change generates no transactions, and therefore doesn't go to the cloud.
If you have existing data when you add iCloud, you'll need to migrate the data to a new data store to force transactions for those existing records. You can do this fairly easily using NSPersistentStoreCoordinator's migratePersistentStore:toURL:options:withType:error: method. It's not hard, but it's not always obvious that it's necessary.
To get started, I first suggest watching Apple's WWDC videos on iCloud-- especially WWDC 2012's session 227, Using iCloud with Core Data. Next, I suggest extreme caution, because as of today Core Data's iCloud support is still, shall we say, far from being the most reliable of Apple's APIs.
I have created a simple iPhone/iPad app which reads some data from a SQLITE database and shows it on the screen. The database is added to the Xcode project and only needs to be read (not written). In the simulator all this works fine, but when I run this app on my iPhone it is too slow.
I have added some performance profiling to the app, so I was able to determine which part of the app was slow. It appears that opening the connection to the database takes about 0.8 - 0.9 second on the iPhone and about 0.004 second on the iPad. I tested with the SQLLITE framework and also with the FMDB wrapper, but the results were the same.
Why is it so slow on the iPhone? Is there a way to improve the performance?
Thanks,
Danny
How often are you opening it? If you can open it once, and just keep that handle open and reuse it, that would likely solve your problem.
Or is it that this single instance of it opening is too great of a burden?
I have an app that uses an SQLite database. With the advent of iCloud on the rise I'm trying to figure out a good architecture for syncing data between devices. So lets say my app runs on an iPhone, an iPad, and a Mac. How can I keep data in my DB up-to-date on all devices?
My first thought was, I can put the database in the cloud and send transactions. But the device may not always been online and the users need their content at anytime, so that wont work. My other thought was to continue using the local db, and then when a connection is made, to send the cached data to the central db. The problem is I have no ideal where to even begin on something like that. How would I know which data has been sent and not sent, which data to actually send when a connection is made, etc.
So this is my question (we don't have to get into iCloud specifics), using an SQLite database and iCloud (or any storage medium), how can I sync data between multiple devices, but still have the most recent data stored locally on the device?
You might want to checkout Couchbase Mobile. This would help with the synchronization you are looking for.
If you have a significant investment into CoreData, then you may want to look at writing your own NSIncrementalStore to support writing data to and from a key value store.
iCloud is only going to be a good solution if your data is sandboxed to a specific user. If you have multiple users that want to view the same data then it won't work.
I'm currently in the middle of developing an iPhone app with a big reference database (using Core Data backed with a pre-populated sqlite database). Once the app is live and deployed to a client's iPhone, I need the facility to update/insert a small amount of data. What are best practices / methods for doing this?
There may be occassions when the frequency of updates will be daily for a month or so. Other occassions when a data update happens once every few months.
What is the recommended way of doing this? Note, I don't anticipate any data model changes for these updates -- this is purely an insert/update of data.
At the moment I'm starting to research the use of push data notifications (q:payload size restrictions?), app store updates (q:code/data model only, not data updates?) and the use of my own ad hoc data server (which the app connects to routinely to check for updates).
Can anyone please provide me any pointers on the above?
Thanks in advance
IIRC Push Notifications have a maximum payload of 256 bytes. Enough for notification purposes, but not more. Your app would still have to download the actual data from your own server after receiving the notification.
Note that the app bundle is not writable on the device. So if your app needs to update the data store, you should copy the pre-populated database file from the app bundle to the app's documents directory on first launch.
App Store updates would certainly be feasible (especially now that Apple seems to have gotten its review process down to a few days at most) but note that an App Store update will always replace the entire app bundle (code and data), so if your pre-populated reference database is big, the customer would have to download it in full every time.
For an iPhone app that has to have a bunch of data inserted before the user can do their thing on first launch, where is the correct place (in the code) to insert that data? I'm looking at between 700 - 800 records total between a few tables.
I initially tried doing it in applicationDidFinishLaunching:. This worked fine for the iPhone 3gs, but caused a consistent first-launch crash on the 3g. After digging into the problem, i found that on the 3g, the app wasn't responding fast enough (presumably because it was busy dumping loads of data into the persistent store), so the OS was killing it under the assumption it was unresponsive.
To fix this problem, I moved the data initialization process out of appdidfinishlaunching and spawned another thread from the first view controller that shows upon launch. This works most of the time, but every once in a while the app crashes with a 134030 error in core data, which according to the apple constants reference, is:
NSPersistentStoreSaveError
Error code to denote that a persistent store returned an error for a save operation. This code pertains to errors such as permissions problems.
This error pops up when calling save: on the managedObjectContext.
Ideally towards the end of development you would populate this data into a Core Data store and add that to your project. On first run, you then copy that store from the app bundle over as the user's Core Data store. This should work for your case.
In the case where this is not possible, one would perform the import on a background thread.