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/

相关文章:

ios - AutoRenewable采购中的完成处理程序崩溃

file - "./..."是否表示所有子文件夹?

file - 如何检查文件是否已在 COBOL 中打开?

ios - 被邀请者如何以编程方式拒绝 Game Center 邀请?

ios - 唯一的应用程序 ID 是否可以在设备上更改?

java - 在 java readLine() 中读取响应结束

java - Strange if 行为的解释

iphone - 在 iOS 设备上禁用应用外视频

iphone - 将新对象添加到 NSMutableArray

iphone - NSNotification 问题