I am checking to see if a user exists in my database, so i send the user's fbid and name to the PHP server and check my database to see if that user exists. However I keep getting NULL when i get the returned array that is suppose to hold the user.
in my console it says:
2014-10-18 13:53:17.385 KandiTAG[1206:60b] checkUser has been called.
2014-10-18 13:53:17.453 KandiTAG[1206:60b] mutableData: <>
Code:
#pragma mark - NSURLConnection Delegate
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[mutableData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[mutableData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
//if we get any connection error manage it here
//for example use alert view to say no internet connection
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSMutableArray *data = [NSJSONSerialization JSONObjectWithData:mutableData options:kNilOptions error:nil];
NSLog(@"mutableData: %@", mutableData);
NSLog(@"response JSON: %@", data);
}
-(void)checkUser {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
FBid = [defaults stringForKey:@"FBID"];
userName = [defaults stringForKey:@"NAME"];
usr = [NSString stringWithFormat:@"user"];
pw = [NSString stringWithFormat:@"password"];
NSLog(@"checkUser has been called");
NSString *requestString = [NSString stringWithFormat:@"user=%@&pw=%@&fbid=%@&username=%@", usr, pw, FBid, userName];
NSData *requestData = [requestString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"example.com/login.php?"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/..." forHTTPHeaderField:@"content-type"];
[request setHTTPBody:requestData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection)
{
mutableData = [[NSMutableData alloc] init];
}
}