iOs:取消执行请求时出错

时间:2015-01-21 12:13:49

标签: ios request nsthread

在我的iOs SpriteKit应用程序中,我在用户操作后的一定时间后使用AVAudioPlayer播放语音,如下所示:

[self.vOSoundManager performSelector:@selector(playVoiceOverWithName:) withObject:@"Voiceover_waarhondenbrokken3" afterDelay:8.0];
[self.vOSoundManager setRequestBeingPerformed:TRUE];

当用户执行其他操作时,声音应停止播放。我是这样做的:

if(self.vOSoundManager.requestBeingPerformed){
            [NSObject cancelPreviousPerformRequestsWithTarget:self.vOSoundManager];
            [self.vOSoundManager stopCurrentSound];
        }

VoiceOverSoundManager中的stopCurrentSound方法:

- (void)stopCurrentSound{
self.playing = FALSE;
[self.voiceOverPlayer stop];
self.voiceOverPlayer = nil;
}

当调用cancelPreviousPerformRequestsWithTarget方法时,我收到以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VoiceOverSoundManager name]: unrecognized selector sent to instance 0x155a9590'

我不知道为什么。有没有人有解决方案?

1 个答案:

答案 0 :(得分:0)

如果您使用一个播放器实例播放游戏中的所有声音,如果您在执行stopCurrentSound方法后不重新创建它,则可能会出现问题:

self.voiceOverPlayer = nil;

尝试删除此行或创建新的播放器实例。