【发布时间】:2011-10-25 03:38:39
【问题描述】:
我正在制作一个应用程序,我需要将某些文件从应用程序包复制到用户的应用程序支持文件夹。这是我实际使用的代码:
NSBundle *thisBundle = [NSBundle mainBundle];
NSString *executableName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *userpath = [paths objectAtIndex:0];
userpath = [userpath stringByAppendingPathComponent:executableName]; // The file will go in this directory
NSString *saveFilePath = [userpath stringByAppendingPathComponent:@"db.sqlite"];
NSFileManager *fileManager = [[NSFileManager alloc] init];
[fileManager copyItemAtPath:[thisBundle pathForResource:@"db" ofType:@"sqlite"] toPath:saveFilePath error:NULL];
但这并没有复制任何东西,顺便说一句,这是一个 Mac 应用程序。
【问题讨论】:
标签: xcode cocoa macos nsfilemanager