在setCompletionBlock中AFNetworking EXC_BAD_ACCESS

kev*_*ber 1 objective-c ios ios5 afnetworking

我正在开发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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

再次感谢!

小智 6

我能够通过更改构建设置来解决这个问题.

在链接头下更改"其他链接器标志",单击-weak_library的条目并将其替换为-weak-lSystem

问题:在iPhone模拟器4.3/XCode 4.2和4.0.2中使用块崩溃应用程序