2012-01-30 135 views
1

我正在使用RestKit iOS包來允許用戶從他們擁有的帳戶提取信息。下面的代碼在第一次完美的工作。但是,如果我嘗試再次使用不同的用戶名和密碼,它只會加載第一個映射調用中的信息。而且,當第二次發送請求時,它會不合理地快速返回數據,這使我相信它只是使用緩存數據。我搜索了高和低的任何方式來重置restkit(及其緩存),並沒有一個工作。這裏是我的代碼:RestKit - RKObjectMapping只運行一次

- (void)login { 
    RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[MyClass class]]; 
    [mapping mapKeyPathsToAttributes: 
    @"Data.MailboxId", @"MailboxId", 
    @"Data.value1", @"Value1", 
    @"Data.value2", @"Value2", 
    nil]; 


    [RKObjectManager objectManagerWithBaseURL:@"https://my.site.com"]; 

    [RKObjectManager sharedManager].client.username = username.text; 
    [RKObjectManager sharedManager].client.password = password.text; 

    [[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/api/v1.0/?format=json" objectMapping:mapping delegate:self]; 
} 

這是我的日誌從RestKit:

2012-01-30 11:59:40.413 HostedNumbers[6909:707] D restkit.network:RKClient.m:265 Reachability observer changed for client <RKClient: 0x6f09640>, suspending queue <RKRequestQueue: 0x6f0a5d0 name=(null) suspended=YES requestCount=0 loadingCount=0/5> until reachability to host '0.0.0.0' can be determined 
2012-01-30 11:59:40.425 HostedNumbers[6909:707] D restkit.network:RKClient.m:389 Reachability to host '0.0.0.0' determined for client <RKClient: 0x6f09640>, unsuspending queue <RKRequestQueue: 0x6f0a5d0 name=(null) suspended=YES requestCount=1 loadingCount=0/5> 
2012-01-30 11:59:40.436 HostedNumbers[6909:707] D restkit.network:RKRequest.m:362 Sending asynchronous GET request to URL https://my.hostednumbers.com/api/v1.0/Mailbox/?format=json. 
2012-01-30 11:59:40.445 HostedNumbers[6909:707] T restkit.network:RKRequest.m:310 Prepared GET URLRequest '<NSMutableURLRequest https://my.hostednumbers.com/api/v1.0/Mailbox/?format=json>'. HTTP Headers: { 
    Accept = "application/json"; 
    "Content-Length" = 0; 
}. HTTP Body: . 
2012-01-30 11:59:43.045 HostedNumbers[6909:707] D restkit.network:RKResponse.m:163 Asked if canAuthenticateAgainstProtectionSpace: with authenticationMethod = NSURLAuthenticationMethodServerTrust 
2012-01-30 11:59:43.513 HostedNumbers[6909:707] D restkit.network:RKResponse.m:163 Asked if canAuthenticateAgainstProtectionSpace: with authenticationMethod = NSURLAuthenticationMethodHTTPDigest 
2012-01-30 11:59:43.516 HostedNumbers[6909:707] D restkit.network:RKResponse.m:137 Received authentication challenge 
2012-01-30 11:59:44.066 HostedNumbers[6909:707] D restkit.network:RKResponse.m:163 Asked if canAuthenticateAgainstProtectionSpace: with authenticationMethod = NSURLAuthenticationMethodServerTrust 
2012-01-30 11:59:45.914 HostedNumbers[6909:707] D restkit.network:RKResponse.m:196 NSHTTPURLResponse Status Code: 200 
2012-01-30 11:59:45.917 HostedNumbers[6909:707] D restkit.network:RKResponse.m:197 Headers: { 
    "Cache-Control" = "no-cache"; 
    "Content-Length" = 2733; 
    "Content-Type" = "application/json; charset=utf-8"; 
    Date = "Mon, 30 Jan 2012 16:59:46 GMT"; 
    Expires = "-1"; 
    Pragma = "no-cache, no-cache"; 
    Server = "Microsoft-IIS/6.0"; 
    "X-AspNet-Version" = "2.0.50727"; 
    "X-Powered-By" = "ASP.NET"; 
} 
2012-01-30 11:59:45.923 HostedNumbers[6909:707] T restkit.network:RKResponse.m:202 Read response body: {"Data":[{"MailboxId":"SP6s2m5zgwze47lsN5bBew2","PhoneNumberList":[{"PhoneNumber":"1-877-564-7397","Description":"(877) 564-7397","Provisioned":true,"PhoneNumberId":"F5MOV_sc3-f9xWcAOCC1Tg2"}],"PhoneNumber":"1-877-564-7397","Prefix":795,"Extension":4920,"ProductId":"_iFmgCPNtTuU1PlknnSqXQ2","ProductCode":"SAR","ProductDescription":"PATLive Messaging Executive","MailboxStatus":1,"BillingStatus":0,"MainMailbox":false,"InfoCode":0,"AliasId":"","FeatureGroupId":"hTw_mObs0ARWkbHxRXZyEw2","FeatureGroupDescription":"Hosted Voicemail/Fax","FeatureGroupIcon":"https://my.hostednumbers.com/images/services/SAR.jpg","ServiceName":"Hosted Voicemail/Fax","MailboxName":"Connor Grady 1","DID":true,"ExtensionDigits":0,"ParentMailboxId":"","NewMessages":4,"SavedMessages":2,"NewVoiceMessages":2,"SavedVoiceMessages":2,"NewFaxMessages":2,"SavedFaxMessages":0,"NewRecordings":0,"SavedRecordings":0},{"MailboxId":"vEqAb2JRNLrP1lB51FVkEw2","PhoneNumberList":[{"PhoneNumber":"1-850-523-3762","Description":"(850) 523-3762","Provisioned":true,"PhoneNumberId":"T-Ykotn8UNweSr4O0jHiqw2"},{"PhoneNumber":"1-888-330-3948","Description":"(888) 330-3948","Provisioned":true,"PhoneNumberId":"KK41mHIFEo5jD9DrzG8_Ig2"},{"PhoneNumber":"1-888-682-8469","Description":"(888) 682-8469","Provisioned":true,"PhoneNumberId":"svD01yJqBrZuJK-HzKvpcQ2"},{"PhoneNumber":"1-888-826-2674","Description":"(888) 826-2674","Provisioned":true,"PhoneNumberId":"zUfxFyXxKXtHB9nMdCs5lg2"},{"PhoneNumber":"1-888-853-4264","Description":"(888) 853-4264","Provisioned":true,"PhoneNumberId":"vmMwo_7x2hYxKa4gAc0PpQ2"},{"PhoneNumber":"1-888-856-2307","Description":"(888) 856-2307","Provisioned":true,"PhoneNumberId":"ViDGc7pJW25kkimk-ObguA2"},{"PhoneNumber":"1-888-856-2742","Description":"(888) 856-2742","Provisioned":true,"PhoneNumberId":"Wpt7fnGXoz8RxcP-xZkl9g2"},{"PhoneNumber":"1-888-858-8276","Description":"(888) 858-8276","Provisioned":true,"PhoneNumberId":"hB-cyJHU-w4BcCVcXmcIsw2"}],"PhoneNumber":"1-850-523-3762","Prefix":795,"Extension":4613,"ProductId":"mLVv-rU2-6GRboN46onbOg2","ProductCode":"CTS","ProductDescription":"Call Tracker Service","MailboxStatus":1,"BillingStatus":0,"MainMailbox":false,"InfoCode":0,"AliasId":"","FeatureGroupId":"v1uO_bCjMNSP9mF90AlO4w2","FeatureGroupDescription":"Hosted Local","FeatureGroupIcon":"https://my.hostednumbers.com/images/services/CTS.jpg","ServiceName":"Hosted Local","MailboxName":"Connor Grady 2","DID":true,"ExtensionDigits":0,"ParentMailboxId":"","NewMessages":0,"SavedMessages":0,"NewVoiceMessages":0,"SavedVoiceMessages":0,"NewFaxMessages":0,"SavedFaxMessages":0,"NewRecordings":0,"SavedRecordings":0}],"ErrorCode":0,"ErrorMessage":"","DataInfo":{"TotalResults":2,"TotalPages":1,"CurrentPage":1,"ResultsPerPage":20}} 
2012-01-30 11:59:45.956 HostedNumbers[6909:5e0f] D restkit.network:RKObjectLoader.m:210 Found directly configured object mapping, creating temporary mapping provider for keyPath '%@' 

- 我的退出發生在這裏,用戶名和密碼,通常應該有回報以下是我的第二個請求身份驗證挑戰 -

2012-01-30 11:59:57.678 HostedNumbers[6909:707] D restkit.network:RKClient.m:265 Reachability observer changed for client <RKClient: 0x6f14400>, suspending queue <RKRequestQueue: 0x6f145b0 name=(null) suspended=YES requestCount=0 loadingCount=0/5> until reachability to host '0.0.0.0' can be determined 
2012-01-30 11:59:57.687 HostedNumbers[6909:707] D restkit.network:RKRequest.m:362 Sending asynchronous GET request to URL https://my.hostednumbers.com/api/v1.0/Mailbox/?format=json. 
2012-01-30 11:59:57.691 HostedNumbers[6909:707] T restkit.network:RKRequest.m:310 Prepared GET URLRequest '<NSMutableURLRequest https://my.hostednumbers.com/api/v1.0/Mailbox/?format=json>'. HTTP Headers: { 
    Accept = "application/json"; 
    "Content-Length" = 0; 
}. HTTP Body: . 
2012-01-30 11:59:57.698 HostedNumbers[6909:707] D restkit.network:RKClient.m:250 Reachability observer changed for RKClient <RKClient: 0x6f14400>, disposing of previous instance: <RKReachabilityObserver: 0x6f15cc0 host=0.0.0.0 isReachabilityDetermined=NO isMonitoringLocalWiFi=565500 reachabilityFlags=-- -------> 
2012-01-30 12:00:00.012 HostedNumbers[6909:707] D restkit.network:RKResponse.m:163 Asked if canAuthenticateAgainstProtectionSpace: with authenticationMethod = NSURLAuthenticationMethodServerTrust 
2012-01-30 12:00:02.076 HostedNumbers[6909:707] D restkit.network:RKResponse.m:196 NSHTTPURLResponse Status Code: 200 
2012-01-30 12:00:02.082 HostedNumbers[6909:707] D restkit.network:RKResponse.m:197 Headers: { 
    "Cache-Control" = "no-cache"; 
    "Content-Length" = 2733; 
    "Content-Type" = "application/json; charset=utf-8"; 
    Date = "Mon, 30 Jan 2012 17:00:02 GMT"; 
    Expires = "-1"; 
    Pragma = "no-cache, no-cache"; 
    Server = "Microsoft-IIS/6.0"; 
    "X-AspNet-Version" = "2.0.50727"; 
    "X-Powered-By" = "ASP.NET"; 
} 
2012-01-30 12:00:02.087 HostedNumbers[6909:707] T restkit.network:RKResponse.m:202 Read response body: {"Data":[{"MailboxId":"SP6s2m5zgwze47lsN5bBew2","PhoneNumberList":[{"PhoneNumber":"1-877-564-7397","Description":"(877) 564-7397","Provisioned":true,"PhoneNumberId":"F5MOV_sc3-f9xWcAOCC1Tg2"}],"PhoneNumber":"1-877-564-7397","Prefix":795,"Extension":4920,"ProductId":"_iFmgCPNtTuU1PlknnSqXQ2","ProductCode":"SAR","ProductDescription":"PATLive Messaging Executive","MailboxStatus":1,"BillingStatus":0,"MainMailbox":false,"InfoCode":0,"AliasId":"","FeatureGroupId":"hTw_mObs0ARWkbHxRXZyEw2","FeatureGroupDescription":"Hosted Voicemail/Fax","FeatureGroupIcon":"https://my.hostednumbers.com/images/services/SAR.jpg","ServiceName":"Hosted Voicemail/Fax","MailboxName":"Connor Grady 1","DID":true,"ExtensionDigits":0,"ParentMailboxId":"","NewMessages":4,"SavedMessages":2,"NewVoiceMessages":2,"SavedVoiceMessages":2,"NewFaxMessages":2,"SavedFaxMessages":0,"NewRecordings":0,"SavedRecordings":0},{"MailboxId":"vEqAb2JRNLrP1lB51FVkEw2","PhoneNumberList":[{"PhoneNumber":"1-850-523-3762","Description":"(850) 523-3762","Provisioned":true,"PhoneNumberId":"T-Ykotn8UNweSr4O0jHiqw2"},{"PhoneNumber":"1-888-330-3948","Description":"(888) 330-3948","Provisioned":true,"PhoneNumberId":"KK41mHIFEo5jD9DrzG8_Ig2"},{"PhoneNumber":"1-888-682-8469","Description":"(888) 682-8469","Provisioned":true,"PhoneNumberId":"svD01yJqBrZuJK-HzKvpcQ2"},{"PhoneNumber":"1-888-826-2674","Description":"(888) 826-2674","Provisioned":true,"PhoneNumberId":"zUfxFyXxKXtHB9nMdCs5lg2"},{"PhoneNumber":"1-888-853-4264","Description":"(888) 853-4264","Provisioned":true,"PhoneNumberId":"vmMwo_7x2hYxKa4gAc0PpQ2"},{"PhoneNumber":"1-888-856-2307","Description":"(888) 856-2307","Provisioned":true,"PhoneNumberId":"ViDGc7pJW25kkimk-ObguA2"},{"PhoneNumber":"1-888-856-2742","Description":"(888) 856-2742","Provisioned":true,"PhoneNumberId":"Wpt7fnGXoz8RxcP-xZkl9g2"},{"PhoneNumber":"1-888-858-8276","Description":"(888) 858-8276","Provisioned":true,"PhoneNumberId":"hB-cyJHU-w4BcCVcXmcIsw2"}],"PhoneNumber":"1-850-523-3762","Prefix":795,"Extension":4613,"ProductId":"mLVv-rU2-6GRboN46onbOg2","ProductCode":"CTS","ProductDescription":"Call Tracker Service","MailboxStatus":1,"BillingStatus":0,"MainMailbox":false,"InfoCode":0,"AliasId":"","FeatureGroupId":"v1uO_bCjMNSP9mF90AlO4w2","FeatureGroupDescription":"Hosted Local","FeatureGroupIcon":"https://my.hostednumbers.com/images/services/CTS.jpg","ServiceName":"Hosted Local","MailboxName":"Connor Grady 2","DID":true,"ExtensionDigits":0,"ParentMailboxId":"","NewMessages":0,"SavedMessages":0,"NewVoiceMessages":0,"SavedVoiceMessages":0,"NewFaxMessages":0,"SavedFaxMessages":0,"NewRecordings":0,"SavedRecordings":0}],"ErrorCode":0,"ErrorMessage":"","DataInfo":{"TotalResults":2,"TotalPages":1,"CurrentPage":1,"ResultsPerPage":20}} 
2012-01-30 12:00:02.115 HostedNumbers[6909:3833] D restkit.network:RKObjectLoader.m:210 Found directly configured object mapping, creating temporary mapping provider for keyPath '%@' 
+0

是否會發布RestKit日誌以驗證緩存是否應該受到責備? – mja 2012-01-30 09:47:29

+0

將RestKit日誌添加到原始帖子^ – 2012-01-30 17:06:10

回答

1

答案非常簡單。我剛剛添加了以下代碼行來強制執行基本的HTTP身份驗證,並且它都可以正常工作:

[RKObjectManager sharedManager].client.authenticationType = RKRequestAuthenticationTypeHTTPBasic; 
0

您是否嘗試過更改緩存策略?

f.e.

RKClient* client = [RKClient clientWithBaseURL:APP_URL]; 
client.cachePolicy = RKRequestCachePolicyNone; 

嘗試一下,看看是否可以修正你的問題(暫時)。

+0

我在代碼中添加了以下內容: [RKObjectManager sharedManager] .client.cachePolicy = RKRequestCachePolicyNone; 不幸的是,問題依然存在。 – 2012-01-30 19:41:09