我正在使用iOS应用程序,使用AFNetworking发出http请求时遇到了一些麻烦。
当我运行代码时,出现错误:EXC_BAD_ACCESS(code = 2 address = 0x0)。
我尝试设置setCompletionBlock时发生错误。
我是Objective-C的新手,这让我很困惑。
先感谢您。感谢大家的帮助!
#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
再次感谢!
最佳答案
我可以通过更改构建设置来解决此问题。
在链接标题下,更改“其他链接器标志”,单击-weak_library的条目,然后将其替换为-weak-lSystem
来自问题:Use of Blocks crashes app in iPhone Simulator 4.3/XCode 4.2 and 4.0.2
关于objective-c - setCompletionBlock中的AFNetworking EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10063633/