iOS开发- 文件共享(利用iTunes导入文件, 并且显示已有文件)

实现过程:

1。在应用程序的Info.plist文件中添加Application supports iTunes file sharing键,并将键值设置为YES。

- (void)viewDidLoad {
    [super viewDidLoad];
    _array_FileName=[[NSMutableArray alloc]init];
    _array_FilePath=[[NSMutableArray alloc]init];
    [self getFile];
}
/**
 *  获取NSDocuments文件下的pdf文件
 */
-(void)getFile{
    NSString *DocPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    file_manager=[[NSFileManager alloc]init];
    NSArray *subPaths=[file_manager subpathsAtPath:DocPath];
    for (NSString *path in subPaths) {
        NSArray *arry=[path componentsSeparatedByString:@"."];
        NSString *last=[arry lastObject];
        if ([last isEqualToString:@"pdf"]) {
            [_array_FilePath addObject:[DocPath stringByAppendingPathComponent:path]];
            [_array_FileName addObject:[path lastPathComponent]];
            NSLog(@"filepath:%@  ----- fileName:%@",path,[path lastPathComponent]);
        }
    }
    [_mytableview reloadData];

}
原文地址:https://www.cnblogs.com/niit-soft-518/p/4444047.html