Created
August 17, 2012 22:19
-
-
Save mrsidique/3383238 to your computer and use it in GitHub Desktop.
UID
This file contains hidden or 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
| NSString* api_key = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"]valueForKey:@"api_key"]; | |
| CFUUIDRef uuid; | |
| CFStringRef uuidStr; | |
| uuid = CFUUIDCreate(NULL); | |
| uuidStr = CFUUIDCreateString(NULL, uuid); | |
| NSString* uuidString = [NSString stringWithFormat:@"%@", uuidStr]; | |
| NSDictionary *paramDictionary = [NSDictionary dictionaryWithObject:uuidString forKey:@"token"]; | |
| NSData *params = [NSJSONSerialization dataWithJSONObject:paramDictionary options:NSJSONWritingPrettyPrinted error:NULL]; | |
| id jsonObject = [NSJSONSerialization JSONObjectWithData:params options:0 error:nil]; | |
| NSLog(@"%@", jsonObject); | |
| NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", [[NSUserDefaults standardUserDefaults]objectForKey:@"baseUrl"],@"apn_devices"]]; | |
| NSLog(@"%@", url); | |
| NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:30]; | |
| [request setHTTPMethod:@"POST"]; | |
| [request setHTTPBody:params]; | |
| [request setValue:api_key forHTTPHeaderField:@"authorization"]; | |
| [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError* error) { | |
| int statusCode = [(NSHTTPURLResponse *)response statusCode]; | |
| NSLog(@"%d", statusCode); | |
| if (statusCode == 200 || statusCode == 201) { | |
| [delegate signInDidFinish]; | |
| [self.navigationController popViewControllerAnimated:YES]; | |
| } | |
| else { | |
| errorLabel.hidden = NO; | |
| signInImage.hidden = YES; | |
| } | |
| }]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment