在 iPhone 中下载最大 50 MB 的大型 zip 文件

发布于 2024-10-09 14:07:49 字数 109 浏览 3 评论 0原文

我想在我的 iPhone 中从服务器下载一个最大 50 MB 的大型 zip 文件。所以请任何人建议我如何下载大的 zip 文件。

我有下载普通 zip 文件的实现代码,但我想下载大文件。

I want to download a large zip file from server up to 50 mb in my iphone. so plz can any one suggest how will i download large zip file.

i have implement code for download a normal zip file but i want to download large files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坐在坟头思考人生 2024-10-16 14:07:49

直接取自项目:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

    bytesCount = bytesCount + [data length];
    [receivedData appendData:data]; 

    //If the size is over 10MB, then write the current data object to a file and clear the data
    if(receivedData.length > MAX_DATA_LENGHT){
        [fileHandle truncateFileAtOffset:[fileHandle seekToEndOfFile]]; //setting aFileHandle to write at the end of the file

        [fileHandle writeData:receivedData]; //actually write the data

        [receivedData release];
        receivedData = nil;
        receivedData = [[NSMutableData data] retain];
    }

    [progressView setProgress:(float)bytesCount/sizeOfDownload];
}


- (void)connectionDidFinishLoading:(NSURLConnection*)connection {

    DEBUG(@"Succeeded! Received %d bytes of data",[receivedData length]);

    //  Release and clean some ivars
    //
    [currentConnection release];
    currentConnection = nil;

    [fileHandle writeData:receivedData];
    [receivedData release];
    [fileHandle release];
..

这是开始下载例程的一部分:

...
//  create a path in doc's folder and initialize the file handler
        NSString *temporaryZipPath = [self temporaryZipPathForResource];
        NSMutableData *fake = [[NSMutableData alloc] initWithLength:0];
        BOOL result = [[NSFileManager defaultManager] createFileAtPath:temporaryZipPath
                                                              contents:fake 
                                                            attributes:nil];
        [fake release];

        if (!result) {
            [super showAlertWithErrorDescription:@"Error creating file"];
            return;
        }

        //
        fileHandle = [[NSFileHandle fileHandleForWritingAtPath:temporaryZipPath] retain];

        //
        NSURLRequest *request = [NSURLRequest requestWithURL:[self audioPackageURL]
                                                 cachePolicy:NSURLRequestReloadIgnoringCacheData 
                                             timeoutInterval:60.0f];

        currentConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

        receivedData = [[NSMutableData data] retain];   
...

希望有帮助。

directly taken from project:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

    bytesCount = bytesCount + [data length];
    [receivedData appendData:data]; 

    //If the size is over 10MB, then write the current data object to a file and clear the data
    if(receivedData.length > MAX_DATA_LENGHT){
        [fileHandle truncateFileAtOffset:[fileHandle seekToEndOfFile]]; //setting aFileHandle to write at the end of the file

        [fileHandle writeData:receivedData]; //actually write the data

        [receivedData release];
        receivedData = nil;
        receivedData = [[NSMutableData data] retain];
    }

    [progressView setProgress:(float)bytesCount/sizeOfDownload];
}


- (void)connectionDidFinishLoading:(NSURLConnection*)connection {

    DEBUG(@"Succeeded! Received %d bytes of data",[receivedData length]);

    //  Release and clean some ivars
    //
    [currentConnection release];
    currentConnection = nil;

    [fileHandle writeData:receivedData];
    [receivedData release];
    [fileHandle release];
..

and this is a part of the start download routine:

...
//  create a path in doc's folder and initialize the file handler
        NSString *temporaryZipPath = [self temporaryZipPathForResource];
        NSMutableData *fake = [[NSMutableData alloc] initWithLength:0];
        BOOL result = [[NSFileManager defaultManager] createFileAtPath:temporaryZipPath
                                                              contents:fake 
                                                            attributes:nil];
        [fake release];

        if (!result) {
            [super showAlertWithErrorDescription:@"Error creating file"];
            return;
        }

        //
        fileHandle = [[NSFileHandle fileHandleForWritingAtPath:temporaryZipPath] retain];

        //
        NSURLRequest *request = [NSURLRequest requestWithURL:[self audioPackageURL]
                                                 cachePolicy:NSURLRequestReloadIgnoringCacheData 
                                             timeoutInterval:60.0f];

        currentConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

        receivedData = [[NSMutableData data] retain];   
...

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文