I'm trying to download a large file with MKNetworkKit (iOS7). Currently using the code below:
- (MKNetworkOperation*)downloadFile: (NSString*)url :(NSString*)output {
NSString* fullPath = [documentsPath stringByAppendingPathComponent:output];
MKNetworkOperation *op = [self operationWithURLString:url params:nil httpMethod:@"GET"];
[op addDownloadStream:[NSOutputStream outputStreamToFileAtPath:fullPath append:NO]];
return op;
}
Then I call this from another class like this:
Tools *dl = [[Tools alloc]init];
MKNetworkOperation* op = [dl downloadFile:someURL :[documentsPath stringByAppendingPathComponent:@"someFile.txt"]];
[op onDownloadProgressChanged:^(double prog) {
progressView.progress = prog;
progressLabel.text = [NSString stringWithFormat:@"%.1f%%",prog*100];
}];
[op addCompletionHandler:^(MKNetworkOperation *completedOperation){
//Downloaded file completed here
} errorHandler:^(MKNetworkOperation *completedOperation, NSError *error){
NSLog(@"%@", error);
}];
[dl enqueueOperation: op];
When the download completes the filename shows up in the Documents folder but the file is Zero Bytes and empty. Does MKNetworkKit not like downloading large files?
I found the error, it seems that I have accidentally put the output file in the wrong place. Since the folder did not exist MKNetworkKit did not write it to the documents folder. Specifying the correct path solved it.