Why the data is not saved in database? - iphone

I am trying to save some data from GPS to a local database. First time when i am entering data, it saves all velues. But after clear the data entry sheet it not saved in database. When i quit the app and again save some data, it enters easily. I m confused what happens in my app ? Any help really appreciated.
Thanks in advance.

Try to debug your app. It seems you are passing some wrong arguments. You need to debug your app. You can use FMDB for all the sqlite purpose. It is very easier to use and very easy to manage.

Have you commited the changes in the DataBase?

Before you decide to use database (SQLite) , make sure you really need a database. If all you need is to persist data and retrive it back (and not querying) , try to do archiving / serialization. See Serialization vs. Archiving? for quick info on them
If your requirement is to have a database, #Rahul's suggestion is the best.

Related

How to save data to Firebase RealTime Database in iOS?

As you can see in the picture below, every time I want to save data to the Firebase RealTime Database, I get these red "alerts" and the data won't be saved.
Initially, I thought it was an error of Authentication, but then I configured that too and still can't save data, although I can read it.
Do you know a way to resolve it? Or am I missing something or doing something wrong?
Thanks for your answers :)
If this was an authentication problem, the console would never show the data to begin with.
More likely you have another piece of code somewhere in your app (or in a backend process) that is listening to this same data, and writing back to the same location when it gets called.

Do I need cache if using CoreData

First of all I'm new in ios/swift...
I need to have offline mode of my app.
I'm using Alamofire for all networking getting json, convert to objects and save into the DB (Core-Data). Wanted to know do I need to have additional cache in between (like: Haneke, or DataCache) in case no internet connection or getting from CoreData?
Is DB request fast/convenient enough?
CoreData is very fast (if correctly used). I don't believe it would be necessary to have an additional cache layer.
It would be just a duplication of data that you already have stored in your DB.
By the way all depends from your project use cases. I would not rely on temporary cached data if my app must work without internet connection.
To give you an idea of core data performances so that you can choose what works best for you: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/Performance.html

iPhone = How to check iPhone Sqlite database is modified externally

I am making an iPhone application, in that my all the content is stored in the sqlite database.
Now there is always threat of Jailbreaking and other Spam activity. So Came to know that Mac/windows can access the application directory directly using some softwares.
So I want to keep my database secure as well as If any one shall modify / replace the database then when I start my application I should be get notified using codes that Some changes are made with the database.
With iPhone how this things will be performed can any one suggest ? any tutorial or code ?
I am going to store data in encrypted formate with some Encryption algorithm but how to protect SQLITE database from modification that I want to know.
thanks in advance.
You really can't know.
If you want to make a best-effort, you could do something like compute an sha512 or sha256 checksum of the database, and store that in another file, but it'd require reading the entire database at every application startup and shutdown, which would probably not please the user. That takes time, more time than just letting SQLite3 do its magic on reads and writes.
And someone malicious could modify the stored checksum, too. (It'd be easy enough to figure out how you're doing it, if they have access to your program's object code, so there's no real point in trying to obfuscate a hypothetical hash checking routine.)
Anyway, it's their data, right? :) so if they want to fiddle around behind the scenes, let them have at it. You need to make sure that any inputs you accept on your servers are treated with the same distrust you would use when accepting input from a web browser.

best way to store data locally and update from web from time to time?

I have created an app which displays information in a organized manner about cultural places.
The information is subject to changes, so I want it to be downloaded from the web. But not everytime. Only once in a while, because information doesn't change often.
What I want to do is, the first time the user opens the application, it downloads all data from the web. For the moment, I parse it from an xml (which is about 100Ko), and I get a NSMutableArray of "CulturalPlace" objects. but it is very slow. And what I would like to do is, to store this data locally (in case the user has an iPod touch an is not on a wifi, or if he is on EDGE and does not want to redownload all). So the user updates data only by clicking an "update button" on the top right of the screen. Otherwise it reads it from disk.
I really don't know what could be the best solution. I thought about Core Data, but I have several Tableview imbricated (Rootviewcontroller > ListofPlacesViewController > PlaceViewController) and I really cannot find good tutorial for a simple use like mine. (the iTunes "TopSongs" sample code seems too complex).
I thought also about not parsing the xml, but instead try an NSURLConnection and get a plist file. But I never managed to read anything from the local file.
So my main question is, should I keep the xml parsing method, or should I use another format to tranfert the data from the web? And what is the best way to store and read data like an NSMutableArray of custom Objects ?
Thanks in advance for your help, sorry for my approximate english.
You could use HTML5' localStorage. It's supported by Chrome and FF on the PC and Safari on Mac OS and iPhone (to the best of my knowledge). It acts like a local database. Bear in mind that if the user selects to clear all cookies (or "private settings"), your storage goes away.
You could opt to store the XML locally, and store in NSUserDefaults the date when last updated - then on app launch you can check to see if you have a new file.
ASIHTTPRequest makes it pretty easy to say "Save the contents of this URL to a file". So you'd always save the XML to a file, and always read from that file or fetch XML if it was not yet there.
In my experience XML is indeed much slower to parse than plist, even though they're technically the same thing. Fortunately, plist's are pretty easy to deal with and the API's take care of all of the archiving and de-archiving.
Once you have your data in memory, it probably wouldn't be too hard to convert it to the much faster plist representation, check out this doc for more info: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/Archiving/Archiving.html
If your app is divided into different pages, you might also consider splitting the file into separate files, and only parsing / de-archiving the information you need when you need it (if you did this on a separate thread and displayed a UIProgressView on the main thread, the delay would probably be barely an issue to the user).

Whether Serialization or Database?

I'm developing an application via which one can send sms by directing it to sms server. My problem is I'm supposed to store the messages sent with date,time and also with the names of users to whom the message was sent. What should I use to save that? database Or I should think f 'serialization'? Later on I'll have to display the records containing names of the users and sms according to date and time at which it was sent.
Suggest me something. Thanks.
It depends.
Database is all eggs in one basket and a bit more work to get the data in.
Writing the SMSs to a daily log file type format is much simpler and eggs in many daily files.
If you have to, often, produce fancy complicated reports then go database.
Or go log style now as you can always migrated your data and interface to database later if it becomes neccesary.
A database is your best bet for those kind of records in my opinion. When you have dates, names, other data and the need to relate it, a RDBMS generally will work the best.
If you need to do any kind of querying of your records, the database will win out over a simple serialized-object file; I'd only use the latter approach if you only ever need all of your data at once.
If you want a simple, lightweight DB I'd suggest looking at SQLite, for small apps like what you're describing the convenience and ease-of-use are a major win over using a full-scale 'production' DB engine like MySQL or Postgres. See this answer for more on that.