본문 바로가기

프로그래밍/iOS

[iOS] Sound & Vibrate

○ System Sound 
  - 무음모드일 경우 소리 안남

-(void) doSystemSound
{
    SystemSoundID soundID;

    NSString *soundfile = [[NSBundle mainBundle] pathForResource:@"soundeffect" ofType:@"wav"];

    AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:soundfile], &soundID);

    AudioServicesPlaySystemSound(soundID);
}


○ Alert Sound 

  - 무음모드일 경우 진동 
-(void) doAlertSound
{
    SystemSoundID soundID;

    NSString *soundfile = [[NSBundle mainBundle] pathForResource:@"soundeffect" ofType:@"wav"];

    AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:soundfile], &soundID);

    AudioServicesPlayAlertSound(soundID);
}


○ Vibrate 
  - 진동

-(void) doVibrate
{    
    AudioServicesPlaySystemSound(kSystemSoundID_vibrate);
}

출처 : http://dw1028.tistory.com/146