2
내 프로젝트를 완료했습니다. 그래서 시뮬레이터에서 테스트했는데 모든 것이 정상입니다. 하지만 불행히도이 프로젝트는 실제 아이폰에서 실행되지 않습니다. 이 오류가 발생합니다.'NSInvalidArgumentException'이라는 캐치되지 않은 예외로 인해 앱 종료.
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager copyItemAtPath:toPath:error:]: source path is nil'"
이유가 무엇입니까?
RootViewController *rootViewController;
...
- (void) startApp;
{
[rootViewController init]; // error occured
}
RootViewController이 프로젝트 단순 파일 중 하나입니다 여기 내가 사용하는 몇 가지 코드입니다.
void Game::readData()
{
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"GameInfo.plist"]; //3
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"GameInfo" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//load from savedStock example int value
gameMaxLevel = [[savedStock objectForKey:@"GameMaxLevel"] intValue];
[savedStock release];
}
무효 게임 ::되어, readData() {
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"GameInfo.plist"]; //3
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"GameInfo" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//load from savedStock example int value
gameMaxLevel = [[savedStock objectForKey:@"GameMaxLevel"] intValue];
[savedStock release];
}
은 (는) 더 많은 코드를 공유합니다. copyItemAtPath 메소드는 어디에 사용합니까? – Alin
읽기/쓰기 plist 파일에서 copyitemAtPath 메서드를 사용했습니다. – bTagTiger
GameInfo.plist의 이름이 똑같은지 확인하십시오. iOS는 대소 문자를 구분합니다. – Alin