AudioServicesPlaySystemSound
은 비동기 적이므로 차단할 수 없습니다. 당신이하고 싶은 것은 재생이 끝났을 때 오디오 서비스로 알려주는 것입니다. 너는 AudioServicesAddSystemSoundCompletion
을 통해 할 수있다. 상황이 조금 못생긴 있도록
IT는 C 레벨 API,하지만 당신은 아마 비슷한 원하는 : 당신이 실제로 소리가 재생 및 가정 동안 UI를 차단하려면
// somewhere, a C function like...
void audioServicesSystemSoundCompleted(SystemSoundID ssID, void *clientData)
{
[(MyClass *)clientData systemSoundCompleted:ssID];
}
// meanwhile, in your class' init, probably...
AudioServicesAddSystemSoundCompletion(
soundIDAsYoullPassToAudioServicesPlaySystemSound,
NULL, // i.e. [NSRunloop mainRunLoop]
NULL, // i.e. NSDefaultRunLoopMode
audioServicesSystemSoundCompleted,
self);
// in your dealloc, to avoid a dangling pointer:
AudioServicesRemoveSystemSoundCompletion(
soundIDAsYoullPassToAudioServicesPlaySystemSound);
// somewhere in your class:
- (void)systemSoundCompleted:(SystemSoundID)sound
{
if(sound == soundIDAsYoullPassToAudioServicesPlaySystemSound)
{
NSLog(@"time to do the next thing!");
}
}
당신의 클래스입니다 뷰 컨트롤러를 사용하는 경우 관련 기간 동안 self.view.userInteractionDisable
을 비활성화해야합니다. 분명히하고 싶지 않은 것은 주행 루프를 차단하는 것입니다. 저 메모리 경고와 같은 중요한 시스템 이벤트가 중단되어 잠재적으로 앱이 강제 종료 될 수 있습니다. 장치 회전과 같은 일을 계속하기를 원할 수도 있습니다.