htmliosobjective-csubmit

IOS - How to handle return calls from a RESTful service API


I am using an API to have users create an account within my app.

Now I am able to generate the URL required in objective-C to submit the values and in the API documentation it has the return numbers that will confirm to me what has happened.

My question is how do I relay that information to the user of the app? The return call is shown to me in a HTML page as plain text.

Any ideas?

> 2012-10-03 12:24:31.557 Multi Web[72631:15203] Dictionary list - {
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Length" = 26;
    "Content-Location" = "signup.php";
    "Content-Type" = "text/html";
    Date = "Tue, 02 Oct 2012 23:24:32 GMT";
    P3P = "policyref=\"/w3c/p3p.xml\", CP=\"ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE\"";
    Server = "Apache/2.2.14 (Ubuntu)";
    Status = "200 OK";
    TCN = choice;
    Vary = "negotiate,Accept-Encoding";
    "X-Limit-Key-Limit" = 10000;
    "X-Limit-Key-Remaining" = 9992;
    "X-Limit-Key-Reset" = 236;
    "X-Limit-User-Limit" = 320;
    "X-Limit-User-Remaining" = 319;
    "X-Limit-User-Reset" = 3600;
    "X-Powered-By" = "PHP/5.3.2-1ubuntu4.14";

I got this in my console so I now, I have created the account successfully. In the middle it says Status = "200 OK";

How do I use that particular line? If I can hook up a UIAlertView to that then I am where I want to be.


Solution

  • I'm not sure if your situation is related to this question. According to docs from the getPocket API you are using, i see the following:

    enter image description here

    According to apple docs, the default HTTP method is GET. What you need to do is check the response headers from the API. So what you need to do is change your httpMethod to HEAD like so:

    NSMutableURLRequest *modReq = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"www.somesite.com/?something"]];
        [modReq setHTTPMethod:@"HEAD"];
    

    Then you can read the values from the header with something like so:

    NSURLResponse* response = // the response, from somewhere
    NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields];
    

    You can then get the response values, and tell the user whats up accordingly.