2

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??

2 Answers2

1

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];
Govind Prajapati
  • 957
  • 7
  • 24
1

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))

}
Amrit Sidhu
  • 1,870
  • 1
  • 18
  • 32