问题
I'm sending an objectManager postObject call through RestKit. After 4 attempts that return 403's my 5th attempt isn't picked up and sent out by RestKit. I've verified this using Charles to watch my actual traffic, and by reviewing the RestKit logs, RestKit is getting my request and putting it in the RequestQueue, but it's never taken back out.
My first 4 requests look like this in the RestKit logs (apologies for the wall of log):
D restkit:RKObjectManager.m:171 CacheTimeoutSet: 60.000000 - 60.000000
T restkit.network.queue:RKRequestQueue.m:226 Request <RKObjectLoader: 0x784ac90> added to queue <RKRequestQueue: 0x6501530>
T restkit.network.queue:RKRequestQueue.m:173 Processing request <RKObjectLoader: 0x784ac90> in queue <RKRequestQueue: 0x6501530>
T restkit.network.queue:RKRequestQueue.m:104 Loading count increasing from 0 to 1. Firing requestQueueDidBeginLoading
T restkit.network.queue:RKRequestQueue.m:131 Loading count set to 1 for queue <RKRequestQueue: 0x6501530>
T restkit.network.cache:RKRequestCache.m:106 Found cachePath '<REMOVED>' for <RKObjectLoader: 0x784ac90>
T restkit.network.cache:RKRequestCache.m:123 Determined hasResponseForRequest: <RKObjectLoader: 0x784ac90> => NO
D restkit.network:RKRequest.m:255 Sending asynchronous POST request to URL <REMOVED>.
D restkit.network:RKObjectLoader.m:295 POST or PUT request for source object <TSLAuthenticationContract: 0x7849b30>
Username:<REMOVED>
Campus:<REMOVED>, serializing to MIME Type application/json for transport...
D restkit.object_mapping:RKObjectMappingOperation.m:391 Starting mapping operation...
T restkit.object_mapping:RKObjectMappingOperation.m:231 Mapping attribute value keyPath 'username' to 'Username'
T restkit.object_mapping:RKObjectMappingOperation.m:241 Mapped attribute value from keyPath 'username' to 'Username'. Value: <REMOVED>
T restkit.object_mapping:RKObjectMappingOperation.m:231 Mapping attribute value keyPath 'password' to 'Password'
T restkit.object_mapping:RKObjectMappingOperation.m:241 Mapped attribute value from keyPath 'password' to 'Password'. Value: <REMOVED>
T restkit.object_mapping:RKObjectMappingOperation.m:231 Mapping attribute value keyPath 'campusName' to 'CampusName'
T restkit.object_mapping:RKObjectMappingOperation.m:241 Mapped attribute value from keyPath 'campusName' to 'CampusName'. Value: <REMOVED>
D restkit.object_mapping:RKObjectMappingOperation.m:397 Finished mapping operation successfully...
T restkit.network.cache:RKRequestCache.m:106 Found cachePath '<REMOVED>' for <RKObjectLoader: 0x784ac90>
D restkit.network.cache:RKRequestCache.m:220 Read nil cached headers from cachePath '<REMOVED>' for '<RKObjectLoader: 0x784ac90>'
D restkit.network.cache:RKRequestCache.m:245 Found cached ETag '(null)' for '<RKObjectLoader: 0x784ac90>'
T restkit.network:RKRequest.m:209 Prepared POST URLRequest '<NSMutableURLRequest <REMOVED>>'. HTTP Headers: <REMOVED>.
D restkit.network.queue:RKRequestQueue.m:180 Sent request <RKObjectLoader: 0x784ac90> from queue <RKRequestQueue: 0x6501530>. Loading count = 1 of 4
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
<REMOVED - Multiple Timer messages>
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
D restkit.network:RKResponse.m:105 NSHTTPURLResponse Status Code: 403
However, on my 5th call this happens:
D restkit:RKObjectManager.m:171 CacheTimeoutSet: 60.000000 - 60.000000
T restkit.network.queue:RKRequestQueue.m:226 Request <RKObjectLoader: 0x782a370> added to queue <RKRequestQueue: 0x6501530>
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
<REMOVED - Multiple Timer messages>
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
As you can see, no Processing request log, no Loading count log, nothing after adding the request to the queue. Has anyone experienced this before? Is there some internal counter that is preventing RestKit from making this call again? I have users that aren't very technical and have issues with there passwords and so it's not inconceivable that they could fail to authenticate more than 4 times in a row.
EDIT: After more research it appears that RestKit isn't decrementing the loadingCount flag in the objectLoader when it gets a failed response. Unfortunately I'm not sure how I should go about fixing this. Is it as simple as checking for the 403 in my delegate and removing the request manually if I find it?
EDIT 2: Ok, I was able to force the removal of the failed request by calling RKRequestQueue cancelRequest: in my objectLoader:didFailWithError: delegate method. Not sure if this is the correct way, but it works. I would expect that RestKit internally handled this issue.
Thanks, Rob
回答1:
happend to me also I noticed i got bad exec , so i run the Xcode Profiling and i noticed i was releasing the object running the request to early
after retaining it properly it was solved
回答2:
I put my solution in edits to my question, but to make SO happy here it is again in an accepted answer.
After more research it appears that RestKit isn't decrementing the loadingCount flag in the objectLoader when it gets a failed response. Unfortunately I'm not sure how I should go about fixing this. Is it as simple as checking for the 403 in my delegate and removing the request manually if I find it?
Ok, I was able to force the removal of the failed request by calling RKRequestQueue cancelRequest: in my objectLoader:didFailWithError: delegate method. Not sure if this is the correct way, but it works. I would expect that RestKit internally handled this issue.
来源:https://stackoverflow.com/questions/9894267/5th-consecutive-restkit-call-not-being-sent