2015-01-25 3 views
0

그래서 내 앱이 시뮬레이터에서 완벽하게 잘 실행하지만 난 내 장치를 연결하고 진짜에서 실행하려고 할 때, 나는이 오류를 얻을 좋아요 :이 방법에SKScene unarchiveFromFile 메서드 내 응용 프로그램이 충돌합니까?

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** -[_NSPlaceholderData  
initWithContentsOfFile:options:error:]: nil file argument' 

과 그 인해를 :

+ (instancetype)unarchiveFromFile:(NSString *)file { 
/* Retrieve scene file path from the application bundle */ 
NSString *nodePath = [[NSBundle mainBundle] pathForResource:file ofType:@"sks"]; 
/* Unarchive the file to an SKScene object */ 
NSData *data = [NSData dataWithContentsOfFile:nodePath 
             options:NSDataReadingMappedIfSafe 
             error:nil]; 
NSKeyedUnarchiver *arch = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; 
[arch setClass:self forClassName:@"SKScene"]; 
SKScene *scene = [arch decodeObjectForKey:NSKeyedArchiveRootObjectKey]; 
[arch finishDecoding]; 

return scene; } 

그것은에 의해 발생 구체적으로 "pathForResource : 파일 ofType : @".하지만 난이 오류를 발생시키는 방법 또는 다른 내 장면을로드하고 내 응용 프로그램을 사용하는 가정입니다 이유를 이해 해달라고 SKS "그것을하는 경우 도와 드리겠습니다. GameScene.h를 사용하여 프로그래밍 방식으로 xcode의 장면 디자이너가 아닌 내 장면을 만듭니다.

+0

나는 문제가 무엇인지 잘 모르겠지만, 당신은 SKScene 및 GameScene 클래스를 사용하고 있습니다. 보기 컨트롤러 파일에서 GameScene 클래스를 사용하여 어떤 일이 발생하는지 확인하십시오. – Whirlwind

+0

파일이란 무엇입니까? 대소 문자를 포함하여 파일 이름이 일치합니까? – LearnCocos2D

답변

0

실제 장치에는없는 파일에 액세스하려는 것처럼 보입니다. 아마도 iOS 시뮬레이터에서 얻을 수있는 디렉토리의 파일 (Application Support-folder)에 액세스하고 있지만 실제 iOS 장치에서는 액세스 할 수 없습니다.

코드에 하드 코딩 된 경로가있어이 문제가 발생할 수 있는지 확인하십시오.

0

보관 방법을 모두 함께 사용하지 않아도 문제를 해결할 수있었습니다. 이전 장면을 만들었습니다 :

- (void)viewDidLoad 
    { 
    [super viewDidLoad]; 
    // Configure the view. 
    SKView * skView = (SKView *)self.view; 
    skView.showsFPS = YES; 
    skView.showsNodeCount = YES; 
    /* Sprite Kit applies additional optimizations to improve rendering performance */ 
    skView.ignoresSiblingOrder = YES; 

    // Create and configure the scene. 
    GameScene *scene = [GameScene unarchiveFromFile:@"GameScene"]; 
    scene.scaleMode = SKSceneScaleModeResizeFill; 

    // Present the scene. 
    [skView presentScene:scene]; 
} 

지금 나는이과는 실제 장치에서 잘 작동 변경 : - (무효) viewDidLoad에 { [슈퍼의 viewDidLoad];

// Configure the view. 
SKView * skView = (SKView *)self.view; 
skView.showsFPS = YES; 
skView.showsNodeCount = YES; 

// Create and configure the scene. 
SKScene * scene = [GameScene sceneWithSize:skView.bounds.size]; 
scene.scaleMode = SKSceneScaleModeResizeFill; 

// Present the scene. 
[skView presentScene:scene]; 

}

+0

이렇게하면 GameScene.sks 파일을 사용하지 않은 것입니다. – windsound

관련 문제