-->

Can I save the downloaded files to NSCacheDictiona

2019-09-07 00:02发布

问题:

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.

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

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];

Can I use like this?

回答1:

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

Edit: 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.

specifically:

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.