Reputation: 2956
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!
Upvotes: 1
Views: 2536
Reputation: 1297
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
Upvotes: 6
Reputation: 19544
Welcome to the fun world of Objective-C, @kev_addict!
When you get an EXC_BAD_ACCESS
exception, it helps to have the details, to see what the stack trace looks like for the offending call.
Without any additional information, my gut tells me that your problems lie somewhere in the way you're getting the image data from an array. Is there any reason why you wouldn't have this method take a UIImage
argument? It seems odd to expect that this method takes an array that expects image data--in the second position, no less.
Upvotes: 1