views:

47

answers:

1

Hi,

currently i'm trying to access the files that are transferred using the new ios feature introduced with 3.2.

- (NSString *)getPrivateDocsDir {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Private Documents"];

    NSError *error;
    [[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:&error];   

    return documentsDirectory;

}


 // and then in a method
 NSString *documentsDirectory = [self getPrivateDocsDir];
 NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];

the problem is, this works fine in simulator, but on my iphone, the files array is empty.

any ideas how to access this directory directly?

thanks!

+1  A: 

The Library-Directory is not accessible through iTunes, and "Private Documents" is inside this library directory. The private documents, are, as the name suggests, private. They are intentionally not accessible through iTunes.

If you want to access the documents directory (which is accessible through itunes) replace this

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);

with this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

EDIT: Access the files like this.

- (NSString *)documentsDirectory {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

NSString *documentsDirectory = [self documentsDirectory];
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
fluchtpunkt
if not in private documents, where are the transferred files stored then? http://cl.ly/bfe32afa6e272ebc5d70
choise
they are in the documents directory. wherever you got that private thing from, it was used for something completly different.
fluchtpunkt
thanks this is working great. was a tutorial, don't know.
choise
can i hide my sqlite generated from core data in this list?
choise
put the sqlite into the private dir.
fluchtpunkt