-
-
Save crtr0/5912870 to your computer and use it in GitHub Desktop.
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
#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