gpt4 book ai didi

ios - 无法在ios中下载文件

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

这是我下载一本书的代码

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle]resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];

NSString *filePath= [resourceDocPath stringByAppendingPathComponent:_bookname];//in _bookname i am already getting the value ,say abcd.pdf

NSLog(@"The bookfilepath is %@",filePath);

NSLog(@"the lenght of recieved data is %d", _recievedData.length);//here i get the correct file size also

[_recievedData writeToFile:filePath atomically:YES];

NSFileManager *filemgr;

filemgr = [NSFileManager defaultManager];

if ([filemgr fileExistsAtPath: filePath] == YES)
{
flag=1;
NSLog (@"File exists");
}
else
{
NSLog (@"File not found"); //always this happens in the log
}
}

filePath 处不存在文件。为什么?有趣的是 _recievedData.length 返回了正确的文件大小。

最佳答案

因为你不能写入应用程序包([[NSBundle mainBundle] resourcePath])。

改为写入文档文件夹。

关于ios - 无法在ios中下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30101986/

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