ios - iphone 在检测到接近传感器时振动多次但仅振动一次

标签 ios iphone objective-c ios7

我在该应用程序中开发了一个应用程序,我正在研究接近传感器检测。当接近检测时使手机振动。它运行成功,但是当第二次打开该应用程序并检测到邻近手机不振动条件时,第一次和第二次都会执行。我现在很困惑,请帮我做到这一点。

下面的代码我已经使用过。

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/

相关文章:

ios - 抽屉 TableView : dismiss by pulling down

html - 如何使点击突出显示仅显示在父元素上,而不显示在子元素上?

ios - 使 ScrollView 在被拉到一半时自动拉到一侧?

ios - 使用 SSKeychain 存储在钥匙串(keychain)中的用户名是否总是出现在第 4 个索引中?

ios - Objective-c 项目 : not supported for static libraries 中的 Swift

ios - 从 Storyboard 中展开可防止委托(delegate)被调用

ios - 在 appWillEnterForeground 上重新加载表

iphone - 在构建表格时如何在 UITableViewController 中显示 View ?

iPhone 位置服务已关闭,但应用程序仍能获取位置?

ios - 我有 UIViewController。而UIView里面如何独立检测触摸?