gpt4 book ai didi

iphone - 如何将文件下载到 iPhone 的文件系统?

转载 作者:行者123 更新时间:2023-11-28 18:08:03 25 4
gpt4 key购买 nike

我想从网站下载一堆 pdf 到我的应用程序中的 iPhone 文件系统。因为我不想每次启动应用程序时都下载文件。

在文档中,我找到了一个名为“dataWithContentsOfURL”的函数,但示例代码对我没有帮助。这是正确的方法,还是有更简单的解决方案?

有人可以给我一两个小费吗? ;-)

问候最大

最佳答案

我推荐使用 ASIHTTPRequest ,它写得很好,有文档记录并且易于使用,这是我的应用程序下载类之一的快速示例,它使用 ASIHTTPRequest 下载 JSON 文件:

-(void)downloadJSONData:(NSString *)path destination:(NSString *)destination secure:(BOOL)secure {

if (![self queue]) {
[self setQueue:[[[NSOperationQueue alloc] init] autorelease]];
}

NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:destination error:NULL];

NSURL *url = [NSURL URLWithString:path];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

if(secure){
[request addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@",[ASIHTTPRequest base64forData:[[NSString stringWithFormat:@"%@:%@",self.username,self.password] dataUsingEncoding:NSUTF8StringEncoding]]]];
}
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request setDownloadDestinationPath:destination];
[[self queue] addOperation:request]; //queue is an NSOperationQueue
}

我会看一下 how-to-use page因为它包含了你需要知道的一切。

关于iphone - 如何将文件下载到 iPhone 的文件系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5355483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com