gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:54 24 4
gpt4 key购买 nike

我创建了一些文件,用于在我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com