Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
iOS Code posting a JSON message to Slack using a Webhook
- (void)postJSONToSlack {
// This is the URL to your Slack team and channel
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:@""]];
NSDictionary *requestData = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Test post to NMDevs from iOS.\nSlack Webhook integration.", @"text",
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:requestData options:0 error:&error];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection) {
NSLog(@"Connection Successful");
} else {
NSLog(@"Connection could not be made");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment