Jatin Vashisht
Jatin Vashisht

Reputation: 157

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)

I'm working on a Custom Alarm App and want to use Vibration in my App as soon as the alarm plays and I have used AudioToolbox and used this below code:

AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

and it worked but i want to run continuously vibration in my App.

is there any possible way to implement this??

Upvotes: 2

Views: 2034

Answers (2)

Govind Prajapati
Govind Prajapati

Reputation: 957

you can use NSTimer and call your function which contain vibration code and when you want to stop it you can call NSTimer's release method.

Example code :

    NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 2.0
                                                  target: self
                                                selector:@selector(onTick:)
                                                userInfo: nil repeats:NO];

    -(void)onTick:(id)sender{

        AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

    }

This code will vibrate device continuously with delay of 2 seconds. when you want to stop vibration you can call release method.

Ex. [t release];

Upvotes: 1

Amrit Sidhu
Amrit Sidhu

Reputation: 1950

You will have to repeat your vibration request.

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector:@selector(repeat:) userInfo: nil repeats:NO];

-(void)repeat:(id)sender{

  AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

}

Upvotes: 1

Related Questions