2012-12-06 107 views
0

開始我的RestKit開發,試圖做出第一個請求。從Github拿來這個示例代碼,爲我的課程修改,但在設備上運行後,我沒有看到任何活動的跡象。即沒有回調,沒有崩潰,沒有例外,沒有日誌輸出。我是否認爲它錯了?代碼如下:RestKit 0.20pre2請求後沒有響應

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[FavoritePlace class]]; 

    [mapping addAttributeMappingsFromDictionary:@{@"name": @"name", @"placeId": @"id"}]; 

    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx 

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:@"/favoritePlace/:placeID" keyPath:@"id" statusCodes:statusCodes]; 

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://my.internal.url/v20"]]; 

    RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]]; 

    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) { 
     FavoritePlace *place = [result firstObject]; 
     NSLog(@"Mapped the place: %@", place); 
    } failure:^(RKObjectRequestOperation *operation, NSError *error) { 
     NSLog(@"Failed with error: %@", [error localizedDescription]); 
    }]; 

我正在使用https,正如您所看到的那樣 - 是否支持?

作爲獎勵,任何人都可以提供最簡單的0.20 API代碼示例,只是爲了看看這個東西是否可以工作?

回答

0

在我看來,最好的啓動方式是檢查RKTwitterCoreData應用程序的例子,它總是在新的提交時更新。您可以在這裏看到示例項目:https://github.com/RestKit/RestKit/tree/master/Examples/RKTwitterCoreData

從粘貼的內容看,您的代碼看起來很好。你是否在應用程序委託中初始化RestKit?在這裏看到:https://github.com/RestKit/RestKit/blob/master/Examples/RKTwitterCoreData/Classes/RKTwitterAppDelegate.m

如果你使用的核心數據,你必須設置管理對象存儲,持久性存儲等

還有大量的文檔資料就在API browswer,像RKObjectManager這裏:http://restkit.org/api/0.20.0-pre2/Classes/RKObjectManager.html

+0

謝謝,這可能有所幫助。我已經從Github檢出了整個RestKit項目並試圖構建它。不幸的是,構建失敗,抱怨缺乏AF *類(頭文件未找到)。看起來像缺少一些依賴關係。我試圖在根目錄下運行「pod install」,但是當Cocoapods嘗試獲取「[email protected]:blakewatters/ocmock.git」時,我收到一個我無法驗證的錯誤。我沒有任何Github賬戶,這可能是一個問題嗎?總的來說,我是否正確地在本地構建RestKit? – Haspemulator

+1

如果您的pod安裝失敗(因爲AFNetworking子模塊尚未加載),請隨意使用包含所有外部框架和庫的完整下載軟件包。 https://github.com/RestKit/RestKit/downloads – flashfabrixx