我可以将下载的文件保存到iPhone中的NSCacheDictionary吗? [英] Can I save the downloaded files to NSCacheDictionary in iphone?

查看:69
本文介绍了我可以将下载的文件保存到iPhone中的NSCacheDictionary吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSURLConnection通过我的应用程序下载一些mp3文件.实际上,我可以在哪里保存下载的文件.有人说保存到NSDocumentDirectory中会导致应用程序被拒绝.

I am downloading some mp3 files through my application using NSURLConnection. Actually where can I save the downloaded file. Someone says that saving in to NSDocumentDirectory will lead to app rejection.

我可以将文件保存到NSCacheDictionary并从iTunes中检索它吗?

Can I save the file to NSCacheDictionary and retrieve this from itunes?

我用这段代码将文件保存到NSCacheDictionary

I used this bit of code to save files to NSCacheDictionary

   NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(
                                                            NSCachesDirectory, NSUserDomainMask, YES)
                        objectAtIndex: 0];
   NSString *documentsDirectoryPath = [cachesPath stringByAppendingPathComponent:@"music.mp3"];
  [receivedData writeToFile:documentsDirectoryPath atomically:YES];

我可以这样使用吗?

推荐答案

如果将文件保存到NSCacheDictionary,将无法从iTunes检索它们.

If you save the files to NSCacheDictionary you will not be able to retrieve them from itunes.

修改: 您可以将mp3文件存储到NSDocumentDirectory并设置请勿备份"标志 要设置该标志,您可以查看技术问答QA1719 .

You can store the mp3 files to NSDocumentDirectory and set "do not backup" flag for setting the flag you can check the Technical Q&A QA1719.

有关其他信息,您可以查看文档.

For additional information you can check the docs.

具体是:

将此属性与可以重新创建但需要执行以下操作的数据一起使用 即使在存储空间不足的情况下也能持久保存,以确保您的正常工作 应用程式,或是因为客户希望离线使用时可以使用. 此属性适用于标记的文件,无论它们位于哪个目录中 在其中,包括文档"目录.

Use this attribute with data that can be recreated but needs to persist even in low storage situations for proper functioning of your app or because customers expect it to be available during offline use. This attribute works on marked files regardless of what directory they are in, including the Documents directory.

这篇关于我可以将下载的文件保存到iPhone中的NSCacheDictionary吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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