0

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?

RAS
  • 8,100
  • 16
  • 64
  • 86
neerajPK
  • 293
  • 1
  • 4
  • 17

1 Answers1

0

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.

Himanshu A Jadav
  • 2,286
  • 22
  • 34
  • so where can i save my mp3 file, and want to access it from itunes later. – neerajPK Aug 08 '12 at 05:07
  • okay, i think i can use the "Excluding a File from Backups on iOS 5.1" , is their any issue while backing up the file from itunes? – neerajPK Aug 08 '12 at 05:26
  • @neerajPK No. There is not any issue I know about. It will work like charm. :) – Himanshu A Jadav Aug 08 '12 at 06:11
  • one more doubt please, i used the first code from the link but get SIGABERT error in the line assert([[NSFileManager defaultManager] fileExistsAtPath: [URL1 path]]); , but when i tried with the second bi of code, no issue found. can i use the second method? – neerajPK Aug 08 '12 at 06:26
  • @neerajPK if your app is running for iOS 5.1 you should use the first method it self, you should not use the second method. AS IT IS SUGGESTED IN THE DOCS. if your app is running for iOS 5.0.1 you should use the second method. Below iOS 5.0.1 it does not support to exclude file from backup. For crash can you confirm both the URLs were same and proper. for creating the URL you should use `+ (id)fileURLWithPath:(NSString *)path` method. – Himanshu A Jadav Aug 08 '12 at 07:15
  • can i use the code NSURL *url=[NSURL fileURLWithPath:documentsDirectoryPath]; [self addSkipBackupAttributeToItemAtURL:url]; – neerajPK Aug 08 '12 at 07:40