7
A
回答
5
RestKit現在使用AFNetworking爲它的HTTP層,所以你需要將其設置在Restkit的HttpClient的。 AFNetworking Github上的See this Issue。另外,AFNetworking的創建者Matt並不喜歡輕鬆打開超時屬性的想法(see his reason here)
我希望這能給你一些見解!
5
子類RKHTTPRequestOperation和實現方法
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
NSMutableURLRequest *requestWithTimeout = [request mutableCopy];
[requestWithTimeout setTimeoutInterval:30];
return [super connection:connection willSendRequest:requestWithTimeout redirectResponse:redirectResponse];
}
+0
不適用於我。 RestKit0.26.0我將嘗試這種方法http://stackoverflow.com/a/16885658/3389683 –
2
完整代碼
更精細/描述性的,我的代碼是如下:
RKHTTPRequestOperation_Timeoutable.h
#import "RKHTTPRequestOperation.h"
@interface RKHTTPRequestOperation_Timeoutable: RKHTTPRequestOperation
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
@end
RKHTTPRequestOperation_Timeoutable .m
#import "RKHTTPRequestOperation_Timeoutable.h"
@implementation RKHTTPRequestOperation_Timeoutable
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
NSMutableURLRequest *requestWithTimeout = [request mutableCopy];
[requestWithTimeout setTimeoutInterval:150];//2.5 minutes
return [super connection:connection willSendRequest:requestWithTimeout redirectResponse:redirectResponse];
}
@end
然後(這是幫助我知道,這是不是在其他的答案中提到的部分),您註冊類RKObjectManager。
像這樣(請原諒我的矛盾,這是迅速沒有目標C我的代碼只有段):
RKObjectManager.sharedManager().registerRequestOperationClass(Timeoutable);
相關問題
- 1. iOS/RestKit - 請求超時
- 2. RestKit 0.20.0 - getObjectsAtPath使用JSON HTTP請求的身體
- 3. RestKit 0.27 - 設置請求超時
- 4. Restkit .20請求超時間隔
- 5. 請求超時 - 請求超時
- 6. RestKit 0.20.0-rc1 - POST後的重複對象
- 7. NSURL請求超時請求
- 8. 請求超時
- 9. node.js請求中的超時
- 10. cast.Api.loadMedia()中的請求超時
- 11. ios5中的請求超時
- 12. API.AI中的請求超時
- 13. RestKit:在RKRequestQueue中請求RKRequest
- 14. RestKit請求嘲弄
- 15. POST請求的請求超時(H-12)
- 16. Restkit:在所有的請求
- 17. Corba請求超時
- 18. KSoap請求超時?
- 19. HTTP請求超時
- 20. NSURLSession - 請求超時
- 21. Ajax請求超時
- 22. Web請求超時
- 23. IIS請求超時
- 24. SharePoint - 「請求超時」
- 25. Tomcat請求超時
- 26. 超時ASIHTTP請求
- 27. NSXMLParser - 請求超時
- 28. 請求超時:檢索文件時GET請求超時
- 29. 防止長請求請求超時
- 30. RestKit:區分didLoadResponse中的多個請求:
似乎沒有被設置在超時的方式RestKit 2.0 HTTPClient。 –