Hi all,
I'm having an simple login in my app. When logged in it will go back to the main screen where it 'syncs' data.
At the start of this 'sync' it checks if there is an udid set and an session.
If so, we check this session, update it, and start the syncing.
i.e. user profile data.
Now, my NSURLConnection gives me an empty "session" value from my result once in the 3 or 4 times.
Here is how I retrieve it:
The result I get 1 out of 3/4 times, in my xcode console :
It still goes pass, because the old session and the udid passed the php script. (result == 2)
But then still "session" is empty!?
Here comes the php script. (I simplified it, to always give session 'asd')
(I kicked some things out. I also have an empty(action) : login)
When user_appSession is set
cases:
'udid' (also updates the device udid with the new one provided. and a new session)
'getAccount' (Will give me back my profile info)
All these cases are not kicking in, and is not to be discussed.
Is it possible that NSURLConnection sometimes does not get all information in the middle of the responseData ?
Even with session = 'asd' it comes back blank 1 out of 3/4 times.
However when I do this from my browser, it keeps working. I can keep bombing the page, but it keeps working.
I'm having an simple login in my app. When logged in it will go back to the main screen where it 'syncs' data.
At the start of this 'sync' it checks if there is an udid set and an session.
If so, we check this session, update it, and start the syncing.
i.e. user profile data.
Now, my NSURLConnection gives me an empty "session" value from my result once in the 3 or 4 times.
Here is how I retrieve it:
Code:
NSString *storedSession = [[applicationData firstObject] objectAtIndex: indexOfSession];
NSURL *url=[NSURL URLWithString:@"http://mydomain.com/myApp/sessions.php?action=session"];
NSString *post = [NSString stringWithFormat: @"user_udid=%@&user_appSession=%@", [[applicationData firstObject] objectAtIndex: indexOfUDID], [[applicationData firstObject] objectAtIndex: indexOfSession]];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"Niesters-App" forHTTPHeaderField:@"User-Agent"];
[request setHTTPBody:postData];
//[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if ([response statusCode] >=200 && [response statusCode] <300) {
NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
SBJsonParser *jsonParser = [SBJsonParser new];
NSDictionary *jsonData = (NSDictionary *) [jsonParser objectWithString:responseData error:nil];
NSInteger result = [(NSNumber *) [jsonData objectForKey:@"result"] integerValue];
if(result == 0) {
NSLog(@"No access.. incorrect session???");
return NO;
} else if(result == 1) {
NSLog(@"Session check failed...");
return NO;
} else if(result == 2) {
NSLog(@"Session check success!");
NSString *session = [jsonData objectForKey: @"session"];
NSLog(@"response: %@", responseData);
//Cleanup data
[appData truncatetable:@"userdata"];
//Insert new data
//an insert query with the udid and session for later use.
//macrumors is kicking it out for security :-/
[appData executeQuery:insertSession];
return YES;
} else {
NSLog(@"Unknown... weird error...");
return NO;
}
} else {
serverConnection = NO;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:@"Could not establish a connection with the server. The app data might not be up-to-date" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
return NO;
}
}
The result I get 1 out of 3/4 times, in my xcode console :
Code:
Session check success!
response: {"result":2,"session":"","userlevel":1}
But then still "session" is empty!?
Here comes the php script. (I simplified it, to always give session 'asd')
Code:
header('Content-type: application/json');
$result = '{"result":0}';
if(valueSet($_POST['user_appSession'])) {
$appSessionQ = $dbController->getQuery('user_id, user_level','dns_users','user_udid = "' . mysql_real_escape_string($_POST['user_udid']) . '" AND user_appSession = "' . mysql_real_escape_string($_POST['user_appSession']) . '"');
if($appSessionQ !== 'none') {
switch($action) {
case 'session':
$newSession = 'asd';//newAppSession();
$updateQ = $dbController->updateQuery(array('user_appSession'),
array(mysql_real_escape_string($newSession)),
'users',
'user_udid = "' . mysql_real_escape_string($_POST['user_udid']) . '" AND user_appSession = "' . mysql_real_escape_string($_POST['user_appSession']) . '"');
if($updateQ !== 'error')
$result = '{"result":2,"session":"' . $newSession . '","userlevel":' . $appSessionQ->user_level . '}';
else
$result = '{"result":1}';
break;
echo $result;
(I kicked some things out. I also have an empty(action) : login)
When user_appSession is set
cases:
'udid' (also updates the device udid with the new one provided. and a new session)
'getAccount' (Will give me back my profile info)
All these cases are not kicking in, and is not to be discussed.
Is it possible that NSURLConnection sometimes does not get all information in the middle of the responseData ?
Even with session = 'asd' it comes back blank 1 out of 3/4 times.
However when I do this from my browser, it keeps working. I can keep bombing the page, but it keeps working.
Last edited: