how to run vibrate continuously in iphone?

后端 未结 4 413
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 10:46

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

Include: AudioToolbox framework

Header File:

#         


        
相关标签:
4条回答
  • 2020-12-28 11:16

    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.

    0 讨论(0)
  • 2020-12-28 11:26

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

    0 讨论(0)
  • 2020-12-28 11:39

    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);
      }  
    }
    
    0 讨论(0)
  • 2020-12-28 11:40

    iOS 5 has implemented Custom Vibrations mode. So in some cases variable vibration is acceptable. The only thing is unknown what library deals with that (pretty sure not CoreTelephony) and if it is open for developers. So keep on searching.

    0 讨论(0)
提交回复
热议问题