Last active
August 29, 2015 14:03
-
-
Save paulkaplan/9c4609b9790763ceadbf to your computer and use it in GitHub Desktop.
Getting started with remote function calls on Spark Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) makeSparkRequest { | |
NSString *sparkApi = @"https://api.spark.io/v1/devices"; | |
NSString *deviceId = @"<YOUR_DEVICE_ID>"; | |
NSString *functionName = @"<YOUR_FUNCTION_NAME>"; // registered to cloud using Spark.function("FUNCTION_NAME", FUNCTION); | |
NSString *accessToken = @"<YOUR_ACCESS_TOKEN>"; | |
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"%@/%@/%@\?access_token=%@", | |
sparkApi, | |
deviceId, | |
functionName, | |
accessToken] | |
]; | |
NSLog(@"%@", url); | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; | |
[request setURL:url]; | |
[request setHTTPMethod:@"POST"]; | |
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | |
NSError *error; | |
NSURLResponse *response; | |
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; | |
// ... do something with returned data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment