我最近从ASIHTTPRequest迁移到AFNetworking,这非常棒.但是,我连接的服务器有一些问题,有时会导致我的请求超时.使用ASIHTTPRequest时,可以使用以下选择器在超时时为请求设置重试计数
-setNumberOfTimesToRetryOnTimeout:
Run Code Online (Sandbox Code Playgroud)
这篇文章可以进一步引用,可以重试ASIHTTPRequest吗?
如果你不熟悉这就是AFNetworking https://github.com/AFNetworking/AFNetworking#readme
我无法在AFNetworking中找到等效的api,是否有人找到了在使用AFNetworking超时的情况下重试网络请求的解决方案?
这是我想要做的比较操作:
// foobar is the name of an ivar on some class
// i.e. NSDate *foobar;
const char *ivarType = [self getTypeForInstanceVariableWithName:@"foobar"];
const char *objType = @encode(NSDate);
if (strcmp(ivarType, objType) == 0) {
//set value
}
NSLog(@"comparing %s with %s", ivarType, objType);
Run Code Online (Sandbox Code Playgroud)
辅助方法:
- (const char*)getTypeForInstanceVariableWithName:(NSString *)name {
return ivar_getTypeEncoding(class_getInstanceVariable([self class], [name cStringUsingEncoding:NSUTF8StringEncoding]));
}
Run Code Online (Sandbox Code Playgroud)
NSLog结果:
comparing @"NSDate" with {NSDate=#}
Run Code Online (Sandbox Code Playgroud)
为什么@encode会返回与ivar_getTypeEncoding()不同的类型语法?有没有更好的方法来完成这种类型的决定?我必须在这里遗漏一些东西......谢谢!