Ios4 iOS 4.3对AFNetworking的支持-可能存在哪些问题?
我已经开发了一个支持iOS 4.3+的应用程序。我想换工作 但文档上说我应该使用0.10.x模块,而不是当前的模块。 使用AFNetworking的当前代码(1.x)的问题是():Ios4 iOS 4.3对AFNetworking的支持-可能存在哪些问题?,ios4,afnetworking,Ios4,Afnetworking,我已经开发了一个支持iOS 4.3+的应用程序。我想换工作 但文档上说我应该使用0.10.x模块,而不是当前的模块。 使用AFNetworking的当前代码(1.x)的问题是(): 1.x中的ARC介绍 使用 imp_实现与block()API差异 但是iOS4.3支持ARClite,通过1.x的代码,我没有发现任何使用弱引用的属性会导致问题。 iOS 4.3支持 只有两个引用使用了NSJSONSerialization,我将它们更改为JSONKit调用-> diff --git a/AFNet
diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m
index 62fc30a..3a60da5 100755
--- a/AFNetworking/AFHTTPClient.m
+++ b/AFNetworking/AFHTTPClient.m
@@ -24,6 +24,7 @@
#import "AFHTTPClient.h"
#import "AFHTTPRequestOperation.h"
+#import "JSONKit.h"
#import <Availability.h>
@@ -163,7 +164,7 @@ - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding
static NSString * AFJSONStringFromParameters(NSDictionary *parameters) {
NSError *error = nil;
- NSData *JSONData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];;
+ NSData *JSONData = [parameters JSONDataWithOptions:JKSerializeOptionNone error:&error];
if (!error) {
return [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];
diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m
index 607f247..c7367dc 100755
--- a/AFNetworking/AFJSONRequestOperation.m
+++ b/AFNetworking/AFJSONRequestOperation.m
@@ -21,6 +21,7 @@
// THE SOFTWARE.
#import "AFJSONRequestOperation.h"
+#import "JSONKit.h"
static dispatch_queue_t af_json_request_operation_processing_queue;
static dispatch_queue_t json_request_operation_processing_queue() {
@@ -66,7 +67,7 @@ - (id)responseJSON {
if ([self.responseData length] == 0) {
self.responseJSON = nil;
} else {
- self.responseJSON = [NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error];
+ self.responseJSON = [self.responseData objectFromJSONDataWithParseOptions:JKSerializeOptionNone error:&error];
}
self.JSONError = error;
diff--git a/AFNetworking/AFHTTPClient.mb/AFNetworking/AFHTTPClient.m
索引62fc30a..3a60da5 100755
---a/AFNetworking/AFHTTPClient.m
+++b/AFNetworking/AFHTTPClient.m
@@ -24,6 +24,7 @@
#导入“AFHTTPClient.h”
#导入“AFHTTPRequestOperation.h”
+#导入“JSONKit.h”
#进口
@@-163,7+164,7@@@-(NSString*)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding
静态NSString*AFJSONStringFromParameters(NSDictionary*parameters){
n错误*错误=nil;
-NSData*JSONData=[NSJSONSerialization dataWithJSONObject:参数选项:0错误:&error];;
+NSData*JSONData=[参数JSONDataWithOptions:JKSerializeOptionNone错误:&错误];
如果(!错误){
return[[NSString alloc]initWithData:JSONData encoding:NSUTF8StringEncoding];
diff——git a/AFNetworking/AFJSONRequestOperation.mb/AFNetworking/AFJSONRequestOperation.m
索引607f247..c7367dc 100755
---a/AFNetworking/AFJSONRequestOperation.m
+++b/AFNetworking/AFJSONRequestOperation.m
@@ -21,6 +21,7 @@
//软件。
#导入“AFJSONRequestOperation.h”
+#导入“JSONKit.h”
静态调度队列AFJSON请求操作处理队列;
静态调度队列json请求操作处理队列(){
@@-66,7+67,7@@@1(id)响应{
如果([self.responseData length]==0){
self.responseJSON=nil;
}否则{
-self.responseJSON=[NSJSONSerialization JSONObjectWithData:self.responseData选项:0错误:&error];
+self.responseJSON=[self.responseData objectFromJSONDataWithParseOptions:JKSerializeOptionNone error:&error];
}
self.JSONError=错误;
虽然这种方式编译起来很漂亮,但我仍然对这种方式持怀疑态度。这是一种正确的方式吗?有一些东西可以让AFNetworking>=1.0在iOS<5上编译,但不建议这样做,因为后续版本中可能会发生其他突破性的更改
但是,如果您对创建一个不能包含主线错误修复和功能的fork感到满意,那么您的方法本身就没有什么问题。好问题!您解决了吗?我也想知道答案。@nanshi是的,我已经放弃了对iOS 4.3的支持。AFNetworking社区没有任何答案,所以我无法回答请确保我所做的是正确的。此外,XCode停止提供支持iOS 4.3的iPhone模拟器(我推断这是苹果向前进的信号)。因此,我的应用程序现在只支持iOS 5+,非常感谢提供的信息!对我来说非常有用:)