Skip to content

Instantly share code, notes, and snippets.

@crtr0
Forked from kwhinnery/sample.mm
Last active December 19, 2015 06:39
Show Gist options
  • Save crtr0/5912870 to your computer and use it in GitHub Desktop.
Save crtr0/5912870 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://your-domain.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