2012-01-14 1 views
1

私はiOSの開発に比較的新しいし、RestKitに慣れようとしています。Restachチュートリアルのコードを取得する

JSONを受信して​​オブジェクトにマッピングするiOS 5アプリケーションを開発しています(重要な場合はARCが有効です)。 Restkitのチュートリアルを検索すると、this oneが見つかりました。しかし、サンプルコードの簡易版がある(セクション「RKClientと実際の生活の例」の1)は次のエラーで失敗します。

2012-01-14 22:15:55.124 Test_StaticLibInApp[789:707] *** Assertion failure in -[RKRequestQueue removeRequest:decrementCounter:], /Users/m/Documents/devel/ios/RestKit/Code/Network/RKRequestQueue.m:350 
2012-01-14 22:15:55.129 Test_StaticLibInApp[789:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to decrement loading count below zero' 

正確には、ここで私が試してみましたコードです

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    RKClient *client = [RKClient clientWithBaseURL:@"some_url"]; 
    RKLogConfigureByName("RestKit/Network", RKLogLevelTrace); 

    NSDictionary *queryParameters = [NSDictionary dictionaryWithObjectsAndKeys:nil]; 
    NSString *getResourcePath = RKPathAppendQueryParams(@"some_url_segment", queryParameters); 
    RKRequest *request = [client get:getResourcePath delegate:self]; 
    [request sendAsynchronously]; 
} 

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response 
{ 
    id jsonParser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON]; 
    NSError *error = nil; 
    id parsedResponse = [jsonParser objectFromString:[response bodyAsString] error:&error]; 
    if (error == nil) 
    { 
     NSLog(@"GET returned with HTTP Code %d and parsedContent: %@", [response statusCode], parsedResponse); 
    } 
    else 
    { 
     NSLog(@"Error: %@", error); 
    } 
} 

- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error 
{ 
    NSLog(@"Failure of GET with error %@.", error); 
} 

ここでトレース出力です:

2012-01-14 22:15:54.746 Test_StaticLibInApp[789:707] I restkit:RKLog.m:30 RestKit initialized... 
2012-01-14 22:15:54.765 Test_StaticLibInApp[789:707] D restkit.network:RKRequest.m:365 Sending asynchronous GET request to URL <url>. 
2012-01-14 22:15:54.771 Test_StaticLibInApp[789:707] T restkit.network:RKRequest.m:313 Prepared GET URLRequest '<NSMutableURLRequest url>'. HTTP Headers: { 
    "Content-Length" = 0; 
}. HTTP Body: . 
2012-01-14 22:15:54.852 Test_StaticLibInApp[789:707] I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer <RKReachabilityObserver: 0x15c920 host=<server ip> isReachabilityDetermined=YES isMonitoringLocalWiFi=448340 reachabilityFlags=-R ------d> 
2012-01-14 22:15:54.857 Test_StaticLibInApp[789:707] D restkit.network:RKClient.m:388 Reachability to host '<server ip>' determined for client <RKClient: 0x158740>, unsuspending queue <RKRequestQueue: 0x15b260 name=(null) suspended=YES requestCount=1 loadingCount=0/5> 
2012-01-14 22:15:55.037 Test_StaticLibInApp[789:707] D restkit.network:RKResponse.m:189 NSHTTPURLResponse Status Code: 200 
2012-01-14 22:15:55.044 Test_StaticLibInApp[789:707] D restkit.network:RKResponse.m:190 Headers: { 
    "Content-Type" = "application/json"; 
    Date = "Sat, 14 Jan 2012 20:16:21 GMT"; 
    Server = "Apache-Coyote/1.1"; 
    "Transfer-Encoding" = Identity; 
} 
2012-01-14 22:15:55.048 Test_StaticLibInApp[789:707] T restkit.network:RKResponse.m:195 Read response body: <json text here> 
2012-01-14 22:15:55.059 Test_StaticLibInApp[789:707] I restkit.network:RKRequest.m:565 Status Code: 200 
2012-01-14 22:15:55.066 Test_StaticLibInApp[789:707] D restkit.network:RKRequest.m:566 Body: <json text here> 
2012-01-14 22:15:55.106 Test_StaticLibInApp[789:707] GET returned with HTTP Code 200 and parsedContent: <json text here> 
2012-01-14 22:15:55.124 Test_StaticLibInApp[789:707] *** Assertion failure in -[RKRequestQueue removeRequest:decrementCounter:], /Users/m/Documents/devel/ios/RestKit/Code/Network/RKRequestQueue.m:350 
2012-01-14 22:15:55.129 Test_StaticLibInApp[789:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to decrement loading count below zero' 
*** First throw call stack: 
(0x33fac8bf 0x341fc1e5 0x33fac7b9 0x3595b3b3 0x1da7f 0x1e7a3 0x3598150f 0x33f78577 0x33f040cf 0x358f53fb 0x1818b 0x2064b 0x359b8c39 0x359106e9 0x359106b3 0x359105d5 0x31fbe8a5 0x31fb3545 0x31fb3243 0x31fb3179 0x33f80b03 0x33f802cf 0x33f7f075 0x33f024dd 0x33f023a5 0x30786fcd 0x37383743 0x2c81 0x2c18) 

は何とかARCを使用してコンパイルされたアプリケーションに関連し、このエラーますか? Restkitのインストールでは、git masterブランチからファイルを入手し、インストールの指示に従いました。設定を変更しませんでした。

ご協力いただきありがとうございます。

答えて

4

[要求sendAsynchronously]

は不要です。

[クライアントが取得:getResourcePathデリゲートを:自己]

は、すでに要求を送信し、要求カウントをデクリメントします。このために

「ゼロを下回るロード・カウントをデクリメントしようとしました」:あなたは

理由を取得しています。

0

RestKitは、ARCを有効にしてコンパイルしないでください。 私がしていることは、シミュレータとデバイス用のRestKitをコンパイルし、その結果の.aとincludeをARC対応プロジェクトに追加することです。 また、他のリンカーフラグに-all_load -ObjCを追加しましたか? よろしく、

+1

私はRestKitをARCとコンパイルしませんでした。 Restkitのインストールでは、git masterブランチからファイルを入手し、[このリンクの]インストール手順(https://github.com/RestKit/RestKit/wiki/Installing-RestKit-in-Xcode-4.x)に従いました。いずれの設定も変更されません。 – alokoko

+0

'' [send sendAsynchronously] 'の行は必要ないと思われます。詳細については、選択した回答を確認してください。 – alokoko

+0

本当に間違いの申し訳ありません。 –

関連する問題