Reputation: 891
Im using ASIFormDataRequest and it is giving me EXC_BAD_ACCESS somewhere with the following code. I enabled NSZombie and as far as I can tell it is something to do with ASIFormDataRequest and it says the responsible library is GraphicsServices.
I have a separate class that holds different methods for getting data back and from my UIViewControllers I can call these methods...
- (Account *) signInAccount:(NSString *)duid user:(NSString *)userName password: (NSString *)passWord
{
Account *myAccount = [[[Account alloc] init] autorelease];
NSURL *apiURL = [NSURL URLWithString:@"http://xxxxxxxxxxxxxxx.com/api.json"];
ASIFormDataRequest *request = [[ASIFormDataRequest requestWithURL:apiURL] autorelease];
[request addPostValue:@"duid025" forKey:@"duid"]; //todo - add the actual passed in value
[request addPostValue:userName forKey:@"user[email]"];
[request addPostValue:passWord forKey:@"user[password]"];
[request setUsername:@"xxxxxxxx"];
[request setPassword:@"yyyyyyyy"];
[request startSynchronous];
int statusCode = request.responseStatusCode;
NSDictionary *json = [request.responseString JSONValue];
NSString *status = [json valueForKeyPath:@"status"];
NSLog(@"API JSON %@", request.responseString);
myAccount.statusCode = statusCode;
if(statusCode == 200)
{
myAccount.status = status;
myAccount.error = @"";
Credentials *myCredentials = [[Credentials alloc] init];
myCredentials.emailAddress = userName;
myCredentials.passWord = passWord;
myAccount.credentials = myCredentials;
//assign division to default division
}
else if(statusCode==403)
{
NSString *error = [json valueForKeyPath:@"error"];
myAccount.status = status;
myAccount.error = error;
}
else
{
// major issue, probably connection
}
return myAccount;
}
Upvotes: 1
Views: 242
Reputation: 1762
I believe the problem is in this line:
ASIFormDataRequest *request = [[ASIFormDataRequest requestWithURL:apiURL] autorelease];
Since you are not allocating and initializing your request object with alloc/init, the object is already autoreleasing. Thus, you are calling autorelease on an object that is already autoreleasing. Try this:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:apiURL];
Upvotes: 1
Reputation: 166
In the line
ASIFormDataRequest *request = [[ASIFormDataRequest requestWithURL:apiURL] autorelease];
you are calling autorelease on an object you do not own. You only need to release objects that you own (i.e. ones that are created using methods containing the names new, alloc or copy).
Change the line to
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:apiURL];
The request object will already be automatically released.
Upvotes: 1