itunes 共享app文件
创建一个项目
File->New->Project, 项目名称BYFileShareWithITunesDemo
配置info.plist文件
<key>UIFileSharingEnabled</key>
<true/>
代码
// 查询电脑往手机传入的文件列表, 输出Documents路径下的所有文件名到控制台
- (void)logFilePathInDocumentsDir:(id)sender {
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent: @"Documents"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:docsDir];
NSString *fileName;
while (fileName = [dirEnum nextObject]) {
NSLog(@"FielName : %@" , fileName);
NSLog(@"FileFullPath : %@" , [docsDir stringByAppendingPathComponent:fileName]) ;
}
}
// 保存到手机里,供手机往电脑分享,向Documents目录保存文件的功能(即共享文件到iTunes)
- (void)createImageFieldToDocuments:(id)sender {
NSFileManager *fileManager=[[NSFileManager alloc] init];
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent: @"Documents"];
NSString *imageFileName = [docsDir stringByAppendingPathComponent:@"myImage.png"] ;
UIImage *image = [self generateImage];
[fileManager createFileAtPath:imageFileName contents:UIImagePNGRepresentation(image) attributes:nil] ;
}