0
在我的应用程序中,我想将我的包中的文件复制到文档目录以修改它。iPhone:找不到资源
这里是我的代码:
+(BOOL) copyDB: (NSString*) pdbName {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES) objectAtIndex: 0];
dbPath = [dbPath stringByAppendingPathComponent: @"myApp"];
dbPath = [dbPath stringByAppendingPathComponent: @"Profiles"];
dbPath = [dbPath stringByAppendingPathComponent: @"ES-EN"];
dbPath = [dbPath stringByAppendingPathExtension: @"prof"];
if([fileManager fileExistsAtPath: dbPath]) {
DebugLog(@"file exists at path %@", dbPath);
return FALSE;
}
NSString *defaultDBPath = [ [ [NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"ES-EN"];
defaultDBPath = [defaultDBPath stringByAppendingPathExtension: @"prof"];
DebugLog(@"dbPath: %@", dbPath);
DebugLog(@"defaultDBPath: %@", defaultDBPath);
if(![fileManager fileExistsAtPath: defaultDBPath]) {
DebugLog(@"Cannot find resource file");
return FALSE;
}
BOOL success = [fileManager copyItemAtPath: defaultDBPath toPath: dbPath error: &error];
if (!success) {
DebugLog(@"!success: Failed to create writable database file with message '%@'.", [error localizedDescription]);
UIAlertView *msg = [[UIAlertView alloc]
initWithTitle:@"Error"
message: [NSString stringWithFormat: @"Failed to create writable database file with message '%@'.", [error localizedDescription] ]
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[msg show];
[msg release];
return FALSE;
}
[ [UserProfile sharedUserProfile] writeInitialData: pdbName];
//Creating fruits folder
NSString *dicDir = [Fruits_Dir stringByAppendingPathComponent: pdbName];
//Does a directory exist?
if (![fileManager fileExistsAtPath: dicDir])
{
//Create a directory
DebugLog(@"Creating userName dir");
if (![fileManager createDirectoryAtPath: dicDir attributes:nil])
{
DebugLog(@"failed to create dicDir");
}
}
return TRUE;
}
我想,这个代码应工作。不知何故,它在模拟器上应该如此,但它不适用于设备。我得到一个资源文件找不到的日志。
可能是什么问题?
谢谢。
一个区别可以是情况。计算机通常不区分大小写,并且iPhone区分大小写。 I.E.你的资源文件实际上被命名为“ES-EN.Prof”? – epatel 2009-08-02 20:26:13
它被完全命名为“ES-EN.prof”... – 2009-08-02 20:39:24