0

I want to develop point-of-sale application for IPAD using InventoryAPI. I know that Erply has a made their own IPAD POS, but I have thoughts to make it little different.

Has anybody used this InventoryAPI and is it simple to use? Ok, my question is that how can I send http queries to server and get response with Cocoa. I'm just starting to learn this and if anyone can point me to some useful link or topic which covers sending http queries, I'll be grateful.

evilone
  • 22,410
  • 7
  • 80
  • 107

1 Answers1

1

There might be an SDK, but if there isn't, you get to learn something new and that's a good thing.

In general, the way you're going to interact with a web-based API is with the NSURLConnection object and it's delegate, NSURLConnectionDelegate.

Have a class that builds a URL, URL Request, and then does the connection. Then you'll create an NSObject subclass, make it conform to the NSURLConnectionDelegate protocol (this is the connection delegate), and implement 4 delegate methods (this is all covered in the class reference). When you've pulled the data down from the server, in your connectionDidFinish method, convert/parse the data and post the resulting object in a notification to a view controller or whatever.

Also, if it's OAuth based, you'll need to write some kind of token manager class, which is basically the same thing... except you'll need to write in handling for different HTTP response codes so the user doesn't need to worry about expired tokens and the like.

Anyways, I'd be happy give more detail... Cocoa actually makes handling this sort of things really simple.

Oh... does this API you're working with do JSON or is it XML? Either way, try and avoid NSXMLParser for now... it's a headache, especially when you just want to get something up and running. (though it's handy to know in general) There are a few really good open-source libraries for that.

Alec Sloman
  • 287
  • 1
  • 9
  • Yes, I read that this APi has both - XML and JSON, so I'll be using JSON for sure :) – evilone Mar 30 '11 at 04:19
  • [Sure there is!](http://cl.ly/5faz) Yes, it's an informal protocol, so it's not neccessary, but if you're subclassing NSObject to act as your connection delegate, you'd better believe if you don't put that in the header, the compiler will [throw a warning.](http://cl.ly/5gsN) – Alec Sloman Apr 01 '11 at 06:32
  • I should add that I don't like declaring my delegates with id keyword instead of the actual subclass. This would negate the need for that declaration, but whatevs. – Alec Sloman Apr 01 '11 at 06:34
  • In fact, yes! I am on Lion for this particular project, which is why I closed down my question (it quickly became apparent that if I was to say, yeah, I'm using Lion, people would shout NDA!). Yes, casting the object to id does generally solve the issue, but not the one I posted, which is intermittent and is fixed with a clean. This is not normal at all and seems like it could be a bug with the new compiler. That said, if the person who posted *this* question is reading these comments, Josh is quite right. – Alec Sloman Apr 01 '11 at 22:45
  • If you're not developing for Lion, you must cast your connection delegate accordingly, otherwise you WILL get compiler warnings. NSURLConnectionDelegate is NOT a formal protocol, so though it appears that in Lion you can treat it as one, you probably shouldn't. – Alec Sloman Apr 01 '11 at 22:50