我在该应用程序中开发了一个应用程序,我正在研究接近传感器检测。当接近检测时使手机振动。它运行成功,但是当第二次打开该应用程序并检测到邻近手机不振动条件时,第一次和第二次都会执行。我现在很困惑,请帮我做到这一点。
下面的代码我已经使用过。
if([[delegate.vibrationdefault stringForKey:@"Vibration"] isEqualToString:@"on"])
{
NSLog(@"Proximity detect with vibration on") ;
[recorder stop];
//AudioServicesPlayalSound (kSystemSoundID_Vibrate) ;
AudioServicesPlayAlertSound (kSystemSoundID_Vibrate) ;
[recorder record];
}
最佳答案
我不太确定这是否能正常工作,但你也许可以这样做:
if([[delegate.vibrationdefault stringForKey:@"Vibration"] isEqualToString:@"on"])
{
NSLog(@"Proximity detect with vibration on") ;
[recorder stop];
//AudioServicesPlayalSound (kSystemSoundID_Vibrate) ;
AudioServicesPlayAlertSound (kSystemSoundID_Vibrate) ;
sleep(1);
AudioServicesPlayAlertSound (kSystemSoundID_Vibrate) ;
sleep(1);
AudioServicesPlayAlertSound (kSystemSoundID_Vibrate) ;
[recorder record];
}
您可以使用下面的sleep(timeInSeconds);
来延迟它。我不确定你是否可以使用 0.5 秒,但你可以尝试一下。
关于ios - iphone 在检测到接近传感器时振动多次但仅振动一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19631759/