Ios iTunes中的UIFileSharingEnabled但文档列表为空

Ios iTunes中的UIFileSharingEnabled但文档列表为空,ios,objective-c,ipad,Ios,Objective C,Ipad,我正在尝试为我的应用启用文件共享。基本上,我需要使用应用程序将一些内容写入csv文件,然后通过iTunes将csv文件从iPad传输到我的macbook 到目前为止,我已经在plist中添加了UIFileSharingEnabled,并将其设置为YES 我还在我的应用程序中添加了以下代码: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSStri

我正在尝试为我的应用启用文件共享。基本上,我需要使用应用程序将一些内容写入csv文件,然后通过iTunes将csv文件从iPad传输到我的macbook

到目前为止,我已经在plist中添加了UIFileSharingEnabled,并将其设置为YES

我还在我的应用程序中添加了以下代码:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];

NSString *dName = [NSString stringWithFormat:@"%@.csv",fileName];

NSString *docName = [documentsPath stringByAppendingPathComponent:dName];

if (![[NSFileManager defaultManager] fileExistsAtPath:documentsPath]){
    [[NSFileManager defaultManager] createFileAtPath:docName contents:nil attributes:nil];
}
NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:docName];
[fileHandle seekToEndOfFile];
[fileHandle writeData:[content dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
NSLog(@"file saved");
NSLog(@"%@",docName);
现在,有趣的是,在NSlog中,确认文件已经创建并保存

MyApp[3674:60b] file saved
MyApp[3674:60b] /var/mobile/Applications/9532F76D-C5D2-4B46-A7BA-7AA24009553B/Documents/TEST.csv
在iTunes中,MyApp列在文件共享应用程序列表中。但是,右边的文档列表是完全空的。不管怎样


请告诉我哪里做错了。提前非常感谢。

您应该替换此代码:

if (![[NSFileManager defaultManager] fileExistsAtPath:documentsPath]){
    [[NSFileManager defaultManager] createFileAtPath:docName contents:nil attributes:nil];
}
与:

if (![[NSFileManager defaultManager] fileExistsAtPath:docName]){
    BOOL success = [[NSFileManager defaultManager] createFileAtPath:docName contents:nil attributes:nil];
    NSLog(@"%d,",success);
}