Has anyone managed to get Server-Sent-Events (SSE) working nicely through AFNetworking? I know AFURLConnectionOperation has an inputStream property I can attach to, but the architecture of AFNetworking seems to be oriented around receiving a response, so I'm not sure what the best way to go about it would be.
Any on how to structure such a program would be appreciated. I'm also open to other iOS libraries, if they provide cleaner solutions.
AFRocketClient (built on top of AFNetworking 2.0) contains AFEventSource which is an implementation of the W3C Event Source API.
The combination of Server Side Events and JSON Patch is being referred to as Rocket.
Related
I am a beginner to ios development.
Can anyone tell me how to send data to server in xcode?
I have a requirement where I need to send device information to a server.
You need to first work out what kind of API the server you're talking to has exposed
Most modern web applications expose a Rest API (although I can only speculate as to what the server you mention is exposing). If Rest, then a good starting point should you not wish to write your own network layer is to use Restkit: https://github.com/RestKit/RestKit
If not Rest, then you need information on what the backend API is, and then go from there...
In it's most basic format you'll need to look at using NSURLRequest and NSURLConnection
NSURLRequest : Post data and read the posted page
http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/
We know that https is different with http by encrypting the content over http tunnel, simply speaking.
For the web browser, since user accept the permission from the popup alter dialog, the browser will get the keys from installed certificates and do the job so on.
For iOS client development, how to handle the digital certificate, and get the public key and encrypt the content via the public key ? thanks,
( By the way, AFnetworking is the famous open source project for iOS developer to handle the http stuff, but seems like that it does not handle the https. (correct me if wrong ) )
NSURLConnection and NSURLSession are the underlying classes used by all HTTP iOS libraries. These two classes does the HTTPS handling for you. Nothing for you to worry about.
Then, you can use libraries as AFNetworking or Hermod that work on top of these basic iOS classes.
AFNetworking is the most popular one.
Hermod is my preferred. It is a new library built on top of AFNetworking and its API is much simpler and easy to use. Also, it has built-in support for OAuth.
It's already done for you.
AFnetworking, the underlying iOS network library it's built on, NSURLConnection and pretty much every networking library (eg, ASIHTTP, etc) all handle the https protocol for you transparently.
Indeed, the very first line on the front page of the AFNetworking github page is an https example:
NSURL *url = [NSURL URLWithString:#"https://alpha-api.app.net/stream/0/posts/stream/global"];
I am developing with lwuit to Nokia and Blackberry.
I am working with server and connections. If I call to server that I am working, all work fine. But, if I try to call to external url that receive jpg, the connection request is stuck and I get responde code 400.
The connection is failed in function performOperation() of class ConnectionRequest.
Why its happen?
If I call to my server and get image its work fine but when I call to external jpg it's don't work.
Is there any solution to this?
All this happen in simulator.
I don't really understand what you are looking for.
But I think you must check the URL of the image. Also, the class com.sun.lwuit.io.services.ImageDownloadService might be very useful to you.
RIM network connections differ from Nokia/standard J2ME due to all sorts of proprietary behaviors added by RIM. Codename One's IO API hides this complexity, if you don't want to migrate I suggest you read up on RIM's networking APN, its a bit complex for a single stack overflow answer.
Add ";deviceside=true" at the end of your url... like "http://myHost/images/flux.jpg;deviceside=true", for Blackberry
I found the problem. This occurs because i use POST method. I think in case that we dont send parametes but use method POST is occurs to problem with Content-Length in header of http message and this the reason that i recieve error(400 or 411)
I'm new to network programming. This is probably a stupid question, would it be okay for my server to be in C++ for my iOS application?
iOS does not care what your server is programmed with. You can use whatever you feel comfortable with. Remember, you aren't going to be sending executable code to the server - you are just going to be sending requests and the server will send a response.
Yes, your server can be written in any way you want, provided you define the correct protocol (method of communication) between your iPhone app (client) and the server.
XML, JSON, HTTP POST or GET's, whatever. It should all work, provided you code both sides correctly.
I've just started to try out RestKit for an iOS app i'm building. I normally use ASIHttpRequest, but I want to test out RestKit mostly for its object mapping between JSON and CoreData. There are some great things about RestKit, but I've run into an issue that really makes it feel deficient, unless I'm doing something wrong or have missed something. I hope someone here can guide me on that.
I'm using RKObjectLoader to make async & sync calls to a REST API. My service is designed to send back proper HTTP status codes, along with some sort of description, a 401 being an example of when the API needs an authenticated user.
My problem is that RestKit stops acting normally if i get a 401 error back. The RKResponse object has a status code of 0, even though it has a payload in it. I'm pretty sure this comes down to NSURLConnection's poor handling of HTTP statuses, but I would expect RestKit to wrap around this somehow. Especially since the RKResponse class has quite a few wrapper functions to determine the status code of the response (isOK, isCreated, isForbidden, isUnauthorized, etc.).
In comparison, ASIHttpRequest doesn't use NSURLConnection, but instead uses the lower level CFNetwork code. ASIHttpRequest allows me to see exactly what came back over HTTP without sending out errors left & right.
Question is, am I doing something wrong, or is this the expected behavior out of RestKit? Has anyone successfully been able to make a calls to [RKResponse isAuthenticated]? Although its inconclusive to me, is there any difference between running in async and sync mode in this regard. I did read somewhere that NSURLConnection run in sync mode will act a bit differently, even though the underlying code is just calling the async operations. Does this have more to do with me using RKObjectLoader as opposed to just RKRequest? Perhaps the fact that the payload can't map to a model causes anger, but it seems that the code is breaking earlier within RKRequest.sendSynchronously, prior to when mapping actually takes place.
Bottom line is my code needs to be able to freely read HTTP status codes. Any guidance would be most appreciated.
Haider
The common way for RestKit 0.20.x is to subclass RKObjectRequestOperation.
I wrote a blog article about this problem which can be found here:
http://blog.higgsboson.tk/2013/09/03/global-request-management-with-restkit/
See http://groups.google.com/group/restkit/msg/839b84452f4b3e26
"... when authentication fails, the authentication challenge gets cancelled and that effectively voids the request."
UPDATE:
RestKit already includes a delegate method for this:
(void)request:(RKRequest *)request didFailAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
Triggers before
(void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error
When HTTP Basic authentication fails, so we can use this instead.