gpt4 book ai didi

ios - AFNetworking 2.0、AFJSONResponseSerializer、AFHTTPResponseSerializer 和并发

转载 作者:行者123 更新时间:2023-11-28 21:56:11 25 4
gpt4 key购买 nike

我有 AFNetworking 2.0 的问题。

我在我的应用中将其用作单例。

一些请求有类似 JSON 格式的类型响应,其他请求有一个简单的 HTTP 状态。

因此,在某些请求中我必须使用 AFJSONResponseSerializer,而在其他请求中我必须使用 AFHTTPResponseSerializer。

有时我遇到崩溃可能是因为在 JSON 响应中由于并发性使用了 AFHTTPResponseSerializer ...

我的请求是这样的:

[self GET:[self _userWithIdBuildUrl:userId] parameters:nil
success:^(NSURLSessionDataTask *task, id responseObject) {

AFJSONResponseSerializer *responseSerializer = [[AFJSONResponseSerializer alloc] init];
self.responseSerializer = responseSerializer;

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;

if (httpResponse.statusCode == SmarfyGetUserProfileNoError) {
//JSON data... In this point I have the crash
}
else {
///
}
}
failure:^(NSURLSessionDataTask *task, NSError *error) {

}];

我可以修复吗?

最佳答案

把这个:AFJSONResponseSerializer *responseSerializer = [[AFJSONResponseSerializer alloc] init];
self.responseSerializer = responseSerializer;
block 外。

关于ios - AFNetworking 2.0、AFJSONResponseSerializer、AFHTTPResponseSerializer 和并发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26461420/

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