I am relatively new to Objective-C but getting there. I am building a small app that accesses a database via NSURLRequests. Upon loading the view, within viewDidLoad, I execute a request to get some data….
NSString *content = [@"http:/localhost/detailAPI.php?token=" stringByAppendingString:token];
content = [content stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(content);
taskData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:content]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
Within connection didReceiveData, I can process the response and put the information on the screen, release taskData. Part of the view is a textfield where the user can add a comment. I then send the comment to the server for insertion into the database using a similar structure.
NSString *updateURL = @"http://localhost/updateAPI.php?update=task&token=";
updateURL =[updateURL stringByAppendingString:token];
updateURL =[updateURL stringByAppendingString:@"&taskname='"];
updateURL =[updateURL stringByAppendingString:taskName.text];
updateURL =[updateURL stringByAppendingString:@"'&comment='"];
updateURL =[updateURL stringByAppendingString:TaskComments.text];
updateURL =[updateURL stringByAppendingString:@"'"];
taskData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:updateURL]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
The first thing that my PHP scripts do is get the data and create an ‘activity’ record. In the first request, I can see the activity record, the data is returned and all is good with the world. With the second request, I see nothing. The app does nothing. I can cancel out and return the main display. I can return to this view and the new comment is not there.
I have tried releasing the connection at the end of the didReceiveData processing, no change. I have tried force starting the connection in the second query with startImmediately set to YES. I have spent about 3 hours on Google and AppleDev and am no wiser. I know this is going to be a simple solution, however I just cannot see it.
Thanks in advance
Chris
In testing this out to find a previous bug, I had commented out the connection release in connectionDidFinishingLoading.