Afnetworking代理方法没有被调用
问题描述:
这是我的代码,请检查我错了。在请求后将不会调用成功或失败的方法。请帮助我。Afnetworking代理方法没有被调用
-(void)downLoadTask {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* mediaKey = [NSString stringWithFormat:@"%@/Sample.m4v", documentsDirectory];
NSLog(@"%@",mediaKey);
NSString *strPath = @"/sites/default/files/media/Master_Talara1_9.mp4";
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:[self.HTTPClient requestWithMethod:@"GET" path:strPath parameters:nil]];
operation.downloadSpeedMeasure.active = YES;
[operation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
NSLog(@"time out");
// Clean up anything that needs to be handled if the request times out
// It may be useful to initially check whether the operation finished or was cancelled
}];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:mediaKey append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
humanReadableRemaingTime = [operation.downloadSpeedMeasure humanReadableRemainingTimeOfTotalSize:totalBytesExpectedToRead numberOfCompletedBytes:bytesRead];
NSLog(@"Time is human read %@",humanReadableRemaingTime);
}];
}
是否有被implemnted任何几种方法得到调用AFNetWorking委托方法
答
你忘了写在代码的函数年底开始下载任务。
[operation start];
你的操作添加一些队列来运行呢? – kirander