views:

1184

answers:

3

I want copy some files to Library or Document in the "Product directory"

but when i add a build phase, and select "Products Directory" in destenation and input my subdir like "Library/xxx/"

when I run the app in simulator, i found nothing int the destenation

and if I set destenation to "Resources", it will be there.

please tell me why and how I can make it?

+1  A: 

Interesting question. I don't know if you can do this as part of the build phase.

To get something into the documents directory, I have a method that runs at app startup like this:

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"filename.txt"];
BOOL success = [fileManager copyItemAtPath:defaultDBPath writablePath error:&error];

That's an incomplete fragment but you probably get the idea. The important thing is the NSDocumentDirectory constant.

Hunter
The original poster wants to install the files at the same time as when the app is being copied over by Xcode. I don't think that is possible. This response has the app installing the files into the Documents directory, at runtime, which isn't the same thing, but the next best thing (AFAIK).
mahboudz
thank u very much, that's helpful
fallhunter
A: 

Add a new build phase -> New Copy Files Build Phase in Target

CiNN
You can't access any of the iPhone directories from Xcode. No?
mahboudz
+1  A: 

The documents directory should only be accessed at runtime. To my knowledge you cannot copy items there during building. What you should do is store those objects that you want in the Documents directory within your bundle and then copy them upon first launch.

Marcus S. Zarra