I've a general question, I've been using NSXMLParser to parse a pretty large XML file containing byte array's of images sent from a web service to the iPhone. I tried switching to AQXMLParser to bring down the memory footprint however now I'm unable to decode my byte arrays in the same way.
When parsing the URL I use foundCharacters to read in the string of the byte[] and pass this to some standard code I found on the net which gives me back the NSData I then use to create my image. The error I'm getting with AQXMLParser is "Application transferred too few scanlines". My suspicion was that because AQXMLParser chunks up the data my parsing class isn't getting enough of the image data in one chunk to enable it to parse the whole image?
Off the top of your head does anyone know why this would work ok with NSXMLParser but not with AQXMLParser? Or can anyone suggest a better way to send images from my web service, pretty new to all of this! The images need to be sent to the device and are then stored locally for future access, hosting them on the web and accessing them via a url is not an option.
Any thoughts that anyone has would be helpful, I can post some code if need be.
Thanks :)
Not directly answering your question, but XML is pretty terrible for binary data. Have you considered hosting it as individual files, or in a zip? ZipArchive is vaguely reasonable.
Related
I have to download 100 thousand JSONS, each JSON not more than 200 characters. I am using AF networking. Is there a way to encode to reduce the size at the server side and send and i should be able to decode at iPhone side.
Moreover has anyone got a method to download the JSONS and store it in the DB on the background thread.Because when i do that directly the UI thread is blocked. Sample Code would be really helpful.
Need the best way to download the HUGE-JSON and store it in the DB.Thanks!
For encoding you can, for example, use gzip-compressed data in your http response that will be unpacked by ios automatically without the need to code anything. Just add "Content-Encoding: gzip" to your http response on the server side. On iOS, i think NSURLRequest accepts gzip encoding by default, or you can set
[request setValue:#"gzip" forHTTPHeaderField:#"Accept-Encoding"]
Of course you can download the JSONS in the background. A good source for information and example code is here http://iosdevelopmentjournal.com/blog/2013/01/27/running-network-requests-in-the-background/
What is the best way to transfer images from a server to an iPhone app? Is sending a base64 string faster or sending a link to the image source and then downloading from this source?
Is sending a base64 string faster
Definitely not - base64 is, on average, 1.4x larger than binary. (http://en.wikipedia.org/wiki/Base64)
or sending a link to the image source and then downloading from this source?
I'm not sure what you mean here - but two requests when you could simply make one (the request for the image) is also not a good idea.
Simply download the image like normal is the best approach.
You could make sure you're making effective use of caching and GZIP (standard HTTP stuff).
The second option is better than first,it would be better to have http link.
just make sure you load the images just once.
I use restful web server to store and retrieve data on mysql database in my server. with strings all work perfect.But What should I do with images ? should i store the image on database or should i send the image on the server with ftp and put the link of image on the database ?
An answer to this would depend on a lot of things. What your restful services do, what their interface is, how your server is configured, how the images are processed, how the images are returned by services, what your client does, etc...
One answer might be - you could uuencode or base64 encode your image and then send that string as the payload in your post method to your restful webservice.
Both work, but I would recommend against using FTP. Consider uploading the data, and then using some scripts to save the file.
Storing images in a database can be a good thing in some scenarios and a bad thing in others. The big advantage is that you only have one system to worry about, the big disadvantage is that the database grows larger and has to do more work. Of course, let's not forget that databases are easier to distribute than files, since they often have built-in mechanisms for that.
Working on an app where all the contents/data for it will be coming via JSON and occasionally i will display a HTML page.
The client is suggesting that maybe we should have some local database(MYSQL Lite) to cache the JSON data returned so we use less of the users data(if there search for the same item again) allowance and because it maybe slightly faster.
Are these good enough reasons for adding the extra complexity and potential problems of having a local DB on the phone?
I didn't think from my experience that the phone was particularly slow or that JSON or HTML were data heavy in there data usage. I'd prefer having a thin client.
Facebook/Twitter/etc work with very little problems using JSON and Html.
Would I be wrong to try steer away from the local DB idea?
Thanks,
-Code
Caching url request results can improve your application's latency over a slow connexion. You could use CoreData to manually manage a cache (key:url, value:request's answer)
Another more elegant solution would be (if you have write access to the webservices) to implement server-side the "if-modified-since" header so that your request data received would be kept at a minimum level.
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).