我该如何解读这张照片?
con是一个NSURLConnection
子类,其中有一个块responseHandler
作为属性保存在其中
执行块后立即写
con.responseHandler = nil;
con = nil;
这张图片是应用程序分析的结果,但我不确定如何理解它
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
WBURLConnectionWithResponseHandler *con = (WBURLConnectionWithResponseHandler *)connection;
NSData *data = [con data];
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Data recieved:%@",responseString);
ServerResponse *response = [ServerResponse handleServerResponse:[con rawResponse] andResponseString:responseString andError:nil];
if(con.responseHandler){
con.responseHandler(response);
}
if(response.statusCode>=500){
if(!self.alert){
self.alert = [[UIAlertView alloc]initWithTitle:WBString(kLocalizable_alert) message:WBString(kLocalizable_serverError) delegate:nil cancelButtonTitle:WBString(kLocalizable_ok) otherButtonTitles: nil];
[self.alert show];
}else {
if(![self.alert isVisible]){
[self.alert setMessage:WBString(kLocalizable_serverError)];
[self.alert show];
}
}
}
con.responseHandler = nil;
[con.data setLength:0];
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
}
typedef void (^ServerResponseHandler)(ServerResponse *response);
这是我的WBURLConnection定义
@interface WBURLConnectionWithResponseHandler : NSURLConnection
@property (nonatomic,strong) ServerResponseHandler responseHandler; <== if i put it to weak or assign, it is deallocated before i can use it
@property (nonatomic,strong) NSHTTPURLResponse *rawResponse;
@property (nonatomic,strong)NSMutableData *data;
@property (nonatomic,assign)NSInteger retries;
@property (nonatomic,strong)NSMutableString *retryCount;
@property (nonatomic,strong)NSString *requestBody;
@property (nonatomic,strong)NSString *stam;
-(BOOL)shouldRetryRequest:(NSError *)error;
@end