Editing for clarification
The userID is generated on the server side, so I don't actually retrieve the userID until after I POST the newly registered username and password. Like so:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSError *error;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
userName.text, @"userName",
password.text, @"password",
nil];
NSData *data = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
NSLog(@"PARAMS = %@", params);
[request setHTTPMethod:@"POST"];
[request setValue:@"text/plain" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:data];
NSURLResponse *response = nil;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc]initWithData:result encoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:result options:0 error:&error];
NSString *results = json[@"result"];
if ([results isEqualToString:@"ok"])
{
[self uploadS3Photo];
NSLog(@"RESULT = %@", responseString);
}
}
End of Edit
I'm not quite sure how to grab the value userID, and post it back as an NSMutableString
.
What I get back from the database is this
2014-02-23 20:52:48.029 TestData[245923:92c] RESULT = {"result":"ok","userId":26}
That number "26", I need to store and then call back to reverse its number, using a method like below.
-(NSString *)reverseString:(NSString *)str {
NSMutableString *reversed = [NSMutableString string];
NSInteger charIndex = [str length];
while (charIndex > 0) {
charIndex--;
NSRange subRange = NSMakeRange(charIndex, 1);
[reversed appendString:[str substringWithRange:subRange]];
}
return reversed;
}