tags:

views:

679

answers:

3

Hi,

In my application I m using following coding pattern to vibrate my iPhone device

Header File:-
AudioServices.h


AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);  

My problem is that when I run my application it gets vibrate but only for second but I want that it will vibrate continuously until I will stop it.

How it could be possible .Please help me out its urgent

Thanks in Advance

+3  A: 

Thankfully, it's not possible to change the duration of the vibration. The only way to trigger the vibration is to play the kSystemSoundID_Vibrate as you have. If you really want to though, what you can do is to repeat the vibration indefinitely, resulting in a pulsing vibration effect instead of a long continuous one. To do this, you need to register a callback function that will get called when the vibration sound that you play is complete:

 AudioServicesAddSystemSoundCompletion (
        kSystemSoundID_Vibrate,
        NULL,
        NULL,
        MyAudioServicesSystemSoundCompletionProc,
        NULL
    );
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Then you define your callback function to replay the vibrate sound again:

#pragma mark AudioService callback function prototypes
void MyAudioServicesSystemSoundCompletionProc (
   SystemSoundID  ssID,
   void           *clientData
);

#pragma mark AudioService callback function implementation

// Callback that gets called after we finish buzzing, so we 
// can buzz a second time.
void MyAudioServicesSystemSoundCompletionProc (
   SystemSoundID  ssID,
   void           *clientData
) {
  if (iShouldKeepBuzzing) { // Your logic here...
      AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 
  } else {
      //Unregister, so we don't get called again...
      AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);
  }  
}
Jason Jenkins
Hello Jason, could you please possibly look at my question? You look pretty smart about this stuff, so maybe you can know the answer. http://stackoverflow.com/questions/3966335/property-in-audio-callback-still-0 thanx
Vanya
+1  A: 

There are numerous examples that show how to do this with a private CoreTelephony call: _CTServerConnectionSetVibratorState, but it's really not a sensible course of action since your app will get rejected for abusing the vibrate feature like that. Just don't do it.

warrenm
+1  A: 

Read the Apple Human Interaction Guidelines for iPhone. I believe this is not approved behavior in an app.

Nick