0

这是交易......我正在创建一个应用程序(从我的另一个应用程序),但我正在改变为只使用 NSDocumentDirectory,这显然允许用户查看所有用户文件,只查看几个文件...即用户创建的 PDF。我有它的工作......但是,在 iTunes 的文件共享/文档窗口中没有显示任何内容。

首先是在持久性模型中调用 NSApplicationSupportDirectory 的方法......

+(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);
    }
}

这是将 PDF 保存到 NSDocumentDirectory 的方法,从其他应用程序没有更改...

- (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

}

我的问题:如何在不暴露其他数据文件的情况下只让用户看到 PDF?现在看来,要么全有,要么全无!

4

1 回答 1

1

我忽略了一个小细节......将应用程序设置为实际共享文件!该应用程序的 info.plist 没有将“应用程序支持 iTunes 文件共享”设置为“是”。(UIFileSharingEnabled)。这么简单的修复!!!

于 2013-08-22T09:35:55.107 回答