Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone:找不到资源_Iphone_Objective C_Cocoa Touch - Fatal编程技术网

iPhone:找不到资源

iPhone:找不到资源,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,在我的应用程序中,我想将一个文件从捆绑包复制到documents目录,以便对其进行修改 这是我的密码: +(BOOL) copyDB: (NSString*) pdbName { NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSString *dbPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirec

在我的应用程序中,我想将一个文件从捆绑包复制到documents目录,以便对其进行修改

这是我的密码:

+(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;
}
我认为这段代码应该可以工作。不知何故,它在模拟器上正常工作,但在设备上不工作。我得到一个无法找到资源文件的日志

有什么问题吗


谢谢。

发生这种情况的一种方法是,资源文件被意外地从您的XCode项目中删除作为引用

如果该文件曾经存在,则可能已安装到模拟器应用程序目录中。即使将其从XCode中删除,该文件仍将保留在那里,并且您的应用程序将在模拟器中工作

但是,一旦您在设备上安装干净,文件就会丢失


确认该文件已列在您的XCode项目资源中,并从模拟器中完全删除该应用程序,然后重试以使所有内容同步。

在某些情况下可能会出现一个差异。计算机通常不区分大小写,iPhone则区分大小写。例如,您的资源文件实际上名为“ES-EN.Prof”?它的名称正是“ES-EN.Prof”…pathForResource:of Type:产生了什么?我用“release”配置而不是“debug”重新构建了应用程序,这次所有资源似乎都按原样复制。怎么会这样?:)在构建应用程序时,所有资源都会在一个称为(适当地)“复制资源”的阶段中复制。检查已断开的配置上的构建阶段,并确保您的资源是该阶段的一部分。