ios - 从 PC 上的 iPhone App 的文档文件夹下载创建的文件

标签 ios iphone file sharing

我创建了一些文件,用于在我的 iPhone 应用程序中存储一些日志信息。它们存储在应用程序的文档文件夹中。我想将它们下载到我的 Mac 上。我可以在 xCode 管理器中看到它们,但无法访问这些文件。我怎样才能做到这一点?

最佳答案

首先,在项目的设置 plist 上设置 Application supports iTunes file sharing。它也可以命名为 UIFileSharingEnabledenter image description here

然后,对于代码,将文件保存在 NSDocumentDirectory 中,如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Id its a local file in the app use its name.  If not, alter for your needs.
    NSString *fileName = @"someFile.png";
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:fileName];
 
    if (![fileManager fileExistsAtPath:documentDBFolderPath]) {
        NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
       [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error];
    }
    [self.window makeKeyAndVisible]; 
    return YES;
}

全部取自iOS Dev Tips - File Sharing from App to iTunes is too easy

关于ios - 从 PC 上的 iPhone App 的文档文件夹下载创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7773399/

相关文章:

c++ - 为什么我的代码两次打印相同的命令行参数?

ios - 如果答案不正确,请防止警报操作关闭 UIAlertController - Swift 4

iphone - 查找 map 上的线和点之间的距离

ios - 如何从 UIImagePickerController 选择多个图像

iphone - 有没有一种简单的方法可以在iPhone中播放m3u?

c - 打开文件问题

iphone - 跨 iOS 平台的视频规范

ios - 谷歌地图 ios 中心的 Objective C 固定标记

iphone - 我的 UITable 正在重复使用不应该使用的单元格!

javascript - PhantomJS 中 evaulate 内部的属性未定义