Domanda

Here is the deal... I am creating an app (from another one of my apps) but I am altering to from using only the NSDocumentDirectory, which obviously allows the user to see all of the user files, to seeing only a few of the files... namely user created PDFs. I have it working... but, nothing shows in the FileSharing/Documents window in iTunes.

First are the methods that invoke the NSApplicationSupportDirectory in the persistence model...

+(NSString *)getDocumentpath
{
    //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}

+(NSString *) documentsDirectoryPath
{
    //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return documentsDirectory;
}

+(void) copyResourceFileToDocumentsDirectory: (NSString *) fileName
{
    //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:fileName];

    NSFileManager * fileManager = [NSFileManager defaultManager];
    BOOL succeeded = [fileManager fileExistsAtPath:writablePath];
    NSError *error;

    //If file is not in the documents directory then only write
    if (!succeeded)
    {
        NSString *newPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
        succeeded = [fileManager copyItemAtPath:newPath toPath:writablePath error:&error];

        if (succeeded == FALSE) {
            NSLog(@"%@ : copy failed", fileName);
        } else {
            NSLog(@"%@ : copy success", fileName);
        }
    } else {
            NSLog(@"%@ : already exists", fileName);
    }
}

This is the method for saving the PDF into the NSDocumentDirectory, which has not been changed from the other app...

- (NSString*)saveJournalToPDF:(UIView*)journal andName:(NSString*)name
{
    NSString* fileName = [NSString stringWithFormat:@"%@.pdf",name];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:fileName];

    ... // the rest of the data strings for creating the PDF

}

My question: how do I get ONLY the PDFs to be visible to the user without exposing the other data files? Right now, it seems that it is either all or nothing!

È stato utile?

Soluzione

I neglected one small detail... setting the app to actually share files! The app's info.plist did not have "Application supports iTunes file sharing" set to YES. (UIFileSharingEnabled). Such a simple fix!!!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top