Я использую пакет RestKit iOS, чтобы пользователь мог получать информацию из своей учетной записи. Код ниже работает отлично с первого раза. Однако, если я попытаюсь использовать другое имя пользователя и пароль во второй раз, он просто загружает информацию из первого вызова сопоставления. Кроме того, когда запрос отправляется во второй раз, он возвращает данные неоправданно быстро, что наводит меня на мысль, что он использует только кэшированные данные. Я искал верх и низ любого способа сброса restkit (и его кеша), и ни один из них не работал. Вот мой код:
- (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 '%@'