0

I want to copy file(image,mp3...) from main bundle to main bundle. To use

[[NSBundle mainBundle]pathForResource:@"copyname" ofType:@"mp3"]

from path = /var/mobile/Applications/62734FAF-1E94-4792-9978-exam/myproject.app/file.mp3

to path = /var/mobile/Applications/62734FAF-1E94-4792-9978-exam/myproject.app/copyname.mp3

function = copyItemAtPath

But i got the error "The operation couldn’t be completed. (Cocoa error 513.)"

Can anyone help me?

Neha
  • 1,751
  • 14
  • 36
Sean
  • 29
  • 1
  • 6

2 Answers2

2

Bundles are read-only, it's not possible to write to them.

There are, however, many places where you can store your data. You can use the Application Support Folder, or for temporary data you can also use the NSTemporaryDirectory() function to get a temporary directory.

This will also work in sandboxed applications.

Community
  • 1
  • 1
IluTov
  • 6,807
  • 6
  • 41
  • 103
-4

Use

NSFileManager *fileManager = [NSFileManager defaultManager];

[fileManager copyItemAtPath:[[NSBundle mainBundle]pathForResource:@"FileNameToBeCopied" ofType:@"mp3"]
                     toPath:[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"NewFileName.mp3"] error:nil];
Neha
  • 1,751
  • 14
  • 36
  • Thank you for the answer.. I already tried it. the same error code " The operation couldn’t be completed. (Cocoa error 513.)" ... – Sean Oct 31 '13 at 08:30