gpt4 book ai didi

objective-c - setCompletionBlock 中的 AFNetworking EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-12-01 17:34:10 28 4
gpt4 key购买 nike

我正在开发一个 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

enter image description here

再次感谢!

最佳答案

我能够通过更改build设置来解决这个问题。

在链接标题下更改“其他链接器标志”,单击 -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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com