Note that there are some explanatory texts on larger screens.

plurals
  1. POExecuting curl based actions in Objective-C
    text
    copied!<p>I am trying to achieve the following in Objective-C:</p> <pre><code>curl -X POST -u "&lt;application key&gt;:&lt;master secret&gt;" \ -H "Content-Type: application/json" \ --data '{"aps": {"badge": 1, "alert": "The quick brown fox jumps over the lazy dog."}, "aliases": ["12345"]}' \ https://go.urbanairship.com/api/push/ </code></pre> <p>Is there some sort of library I can use that achieves this? Obviously I have all of the values ready to go ahead and make my request, but I'm not exactly sure how to do it in Objective-C.</p> <p>I am using TouchJSON, however I'm not quite sure how to construct the correct JSON payload above and POST this to the server (also I'd prefer this to be an asynchronous request rather than a synchronous).</p> <pre><code>NSError *theError = NULL; NSArray *keys = [NSArray arrayWithObjects:@"aps", @"badge", @"alert", @"aliases", nil]; NSArray *objects = [NSArray arrayWithObjects:?, ?, ?, ?, nil]; NSDictionary *theRequestDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; NSURL *theURL = [NSURL URLWithString:@"https://go.urbanairship.com/api/push/"]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0f]; [theRequest setHTTPMethod:@"POST"]; [theRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; NSData *theBodyData = [[CJSONSerializer serializer] serializeDictionary:theRequestDictionary error:&amp;theError]; [theRequest setHTTPBody:theBodyData]; NSURLResponse *theResponse = NULL; NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&amp;theResponse error:&amp;theError]; NSDictionary *theResponseDictionary = [[CJSONDeserializer deserializer] deserialize:theResponseData error:&amp;theError]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload