NSURLConnection下载视频文件有问题

用NSURLConnection实现断点下载视频文件
/**

  • 接受到服务器的响应 *
  • @param connection
  • @param response
    */

    • (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

    if (self.currentLenth) {
    return;
    }

    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)firstObject];
    NSString *filePath = [caches stringByAppendingPathComponent:response.suggestedFilename];

    //创建一个空得文件到沙盒中

    NSFileManager *manager = [NSFileManager defaultManager];

    [manager createFileAtPath:filePath contents:nil attributes:nil];
    //创建一个用来写数据的文件句柄对象

    self.writeHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
    //获取到文件总长度
    self.totalLenth = response.expectedContentLength;
    }
    /**

  • 接收到数据时调用该方法
    *

  • @param data 这次返回的数据
    */

    • (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { //移动到文件的最后面 [self.writeHandle seekToEndOfFile];

    //将数据写入沙盒
    [self.writeHandle writeData:data];

    //累计写入文件的长度
    self.currentLenth = self.currentLenth + data.length;

    //进度条
    self.jindutiao.progress = (double)self.currentLenth/self.totalLenth;
    }

每次点击暂停然后再次下载,最后下载的文件大小大于本来文件大小,虽然能播放但是只能播放第一次暂停前所下载的,后面的就出错

应该暂停后的数据读取位置不对,

是否用的二进制文件大小。用的byte的数组。暂停的时候是否记录正确