适用于iOS的Google Drive API下载文件 [英] Google drive api download file for iOS

查看:46
本文介绍了适用于iOS的Google Drive API下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码下载文件:

I am using this code below for download file:

- (void)downloadFileContentWithService:(GTLServiceDrive *)service
                                  file:(GTLDriveFile *)file
                       completionBlock:(void (^)(NSData *, NSError *))completionBlock {

    if (file.downloadUrl != nil)
    {
        GTMHTTPFetcher *fetcher =
        [service.fetcherService fetcherWithURLString:file.downloadUrl];

        [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
            if (error == nil) {
                // Success.
                completionBlock(data, nil);
            } else {
                NSLog(@"An error occurred: %@", error);
                completionBlock(nil, error);
            }
        }];
    } else {
        completionBlock(nil,
                        [NSError errorWithDomain:NSURLErrorDomain
                                            code:NSURLErrorBadURL
                                        userInfo:nil]);
   }

似乎一切正常,过了一段时间,我从服务器上检索了我的文件.但是文件大小约为250 MB的问题.

Seems everything goes well and after some time I retrieve my file from the server. But the problem that the file size is About 250 MB.

我的问题是,如果文件太大,应用程序将在设备上崩溃.我们需要做一些限制或类似的事情吗?我已经下载了pdf文件.

My question is will app crash on the device if the file size is too big. Do we need to make some restriction or something like this. I have downloaded pdf file.

推荐答案

该应用程序可能会崩溃,因为它在下载到内存期间非常快地增加了内存.您可以直接下载到磁盘上以避免这种情况.似乎您可以使用NSFileHandle * downloadFileHandle; 属性="nofollow"> GTMHTTPFetcher .

The app may crash since it's increasing memory quite fast during downloading into the memory. You can download directly to disk to avoid this. Seems like you can use NSFileHandle *downloadFileHandle; property of GTMHTTPFetcher for this purpose.

这篇关于适用于iOS的Google Drive API下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆