'Simple' post request in IOS app

Hey guys!

I’m in need for some help with programming a simple POST request in an IOS app.

I’m trying to call a function on my spark core with following Objective-C:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.spark.io"]];

[request setHTTPMethod:@"POST"];
[request setValue:@"text" forHTTPHeaderField:@"Content-type"];

NSString *testString = @"/v1/devices/DEVICE-ID/lighton&access_token=MYACCESSTOKEN";

[request setValue:[NSString stringWithFormat:@"%d",
                   [testString length]] forHTTPHeaderField:@"Content-length"];

[request setHTTPBody:[testString
                      dataUsingEncoding:NSUTF8StringEncoding]];           (void) [[NSURLConnection alloc] initWithRequest:request delegate:self];

so far my objective-C…
on the spark core following firmware is running:

int LED = D0;

void setup()
pinMode(LED, OUTPUT);
Spark.function(“lighton”, lighton);

void loop() {


int lighton(String args)

digitalWrite(LED, HIGH);

return 1;

thanks guys !!

Hi @ritch,

A few awesome community members started on an Objective-C wrapper for the api here:

As an example, here’s one of the web requests:

I hope that helps!


Hey David,
thanks for the quick reply!

1 Like