2

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 を使用するリファレンスは 2 つしかなく、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;

これは美しくコンパイルされますが、私はまだこのようにすることに懐疑的です。これは正しい方法ですか?

4

1 に答える 1

1

AFNetworking >= 1.0 を iOS < 5 でコンパイルするために変更できることはありますが、後続のリリースでその他の重大な変更が発生する可能性があるため、これはお勧めしません。

しかし、メインラインのバグ修正や機能を組み込むことができないフォークを作成することに満足している場合は、アプローチに本質的な問題はありません。

于 2013-05-24T20:44:24.703 に答える