当检测到接近传感器时,iphone会多次振动但只有一次

时间:2013-10-28 09:59:00

标签: 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];
}

1 个答案:

答案 0 :(得分:1)

我不太确定这样可以正常工作,但你可以这样做:

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秒,但你可以尝试一下。