I’m working on an iOS app and am having some trouble with making a http request using AFNetworking.
When I run the code I get the error: EXC_BAD_ACCESS(code=2 address=0x0).
The error is occurring when I attempt to setCompletionBlock.
I’m new to Objective-C and this has me stumped.
Thank you in advance. Everyone’s help is appreciated!
#import "AFNetworking.h"
#import <Cordova/CDV.h>
#import "UploadImg.h"
@implementation UploadImg
- (void) uploadImg:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
NSURL *url = [NSURL URLWithString:@"http://test.com/mobile/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = [NSData dataFromBase64String:[arguments objectAtIndex:1]];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:@"TEST_STYLE" forKey:@"styleType"];
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload.php" parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageData name:@"imageName" fileName:@"image.png" mimeType:@"image/png"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error");
}];
[operation start];
}
@end

Thanks again!
I was able to solve this by changing the build settings.
Under the linking header change the “Other linker flags”, click the entry for -weak_library and replace it with -weak-lSystem
From question: Use of Blocks crashes app in iPhone Simulator 4.3/XCode 4.2 and 4.0.2