Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created June 24, 2013 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kwhinnery/5852602 to your computer and use it in GitHub Desktop.
Save kwhinnery/5852602 to your computer and use it in GitHub Desktop.
#pragma mark * UIView methods
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Synchronous networking on the main thread is seriously bad - only doing this for
// demo purposes
NSURL* url = [NSURL URLWithString:@"https://twilionode.azurewebsites.net/capability"];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest: [NSURLRequest requestWithURL:url]
returningResponse:&response
error:&error];
if (data) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
if (httpResponse.statusCode == 200) {
NSString* capabilityToken = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
phone = [[TCDevice alloc] initWithCapabilityToken:capabilityToken
delegate:nil];
}
else {
NSString* errorString = [NSString stringWithFormat: @"HTTP status code %d", httpResponse.statusCode];
NSLog(@"Error generating token: %@", errorString);
}
}
else {
NSLog(@"Error generating token: %@", [error localizedDescription]);
}
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment