0

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?

4

1 回答 1

1

我发现了错误,似乎是我不小心把输出文件放错了地方。由于该文件夹不存在 MKNetworkKit 没有将其写入文档文件夹。指定正确的路径解决了它。

于 2013-10-15T14:22:39.807 回答