【问题标题】:iOS 4.3 support for AFNetworking - What can be the problems?iOS 4.3 对 AFNetworking 的支持 - 可能是什么问题?
【发布时间】:2012-12-17 12:35:34
【问题描述】:

我已经开发了一个支持 iOS 4.3+ 的应用程序。我想从ASIHTTPRequest转移 到 AFNetworking 但在文档上说我应该使用 0.10.x 模块而不是当前模块。 https://github.com/AFNetworking/AFNetworking#requirements 使用 AFNetworking 的当前代码(1.x)的问题是(https://github.com/AFNetworking/AFNetworking/issues/545):

  1. 1.x 中的 ARC 介绍
  2. 使用NSJSONSerialization
  3. imp_implementationWithBlock() API 区别

但是 iOS 4.3 支持 ARClite,并且通过 1.x 的代码,我没有遇到任何使用可能导致问题的弱引用的属性。 http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/ObjCAvailabilityIndex/_index.html iOS 4.3 支持imp_implementationWithBlock() 只有两个引用使用了 NSJSONSerialization,我将它们改为 JSONKit 调用 ->

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;

虽然这编译得很漂亮,但我仍然对这样做持怀疑态度。这是正确的方法吗?

【问题讨论】:

  • 好问题!你解决了吗?我也想知道答案。
  • @nanshi 是的,我已经放弃了对 iOS 4.3 的支持 AFNetworking 社区没有任何答复,所以我不能确定我所做的是否正确。此外,XCode 停止为支持 iOS 4.3 的 iPhone 提供模拟器(我推断这是 Apple 继续前进的迹象)。所以,我的应用现在只支持 iOS 5+
  • 非常感谢您提供的信息!对我很有用:)

标签: ios4 afnetworking


【解决方案1】:

您可以更改一些内容以使 AFNetworking >= 1.0 在 iOS

但是,如果对创建一个无法合并主线错误修复和功能的分支感到满意,那么您的方法本质上没有任何问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多