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

Ios 当检测到接近传感器时,iphone会振动多次,但只有一次,ios,iphone,objective-c,ios7,Ios,Iphone,Objective C,Ios7,我已经开发了一个应用程序在该应用程序中,我正在接近传感器检测工作。当接近检测使手机振动时。它已成功运行,但当第二次打开该应用程序并检测到接近型手机未振动时,第一次和第二次都会执行。我现在很困惑,请帮我做这个 下面的代码我已经用过了 if([[delegate.vibrationdefault stringForKey:@"Vibration"] isEqualToString:@"on"]) { NSLog(@"Proximity detect with vibration on") ;

我已经开发了一个应用程序在该应用程序中,我正在接近传感器检测工作。当接近检测使手机振动时。它已成功运行,但当第二次打开该应用程序并检测到接近型手机未振动时,第一次和第二次都会执行。我现在很困惑,请帮我做这个

下面的代码我已经用过了

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];
}

您可以使用
睡眠(timeinsectonds)在下面延迟它。我不确定你是否能用上0.5秒,但你可以试试。

这是否意味着你只需要振动一次,但它振动了两次?这是你的问题吗?不,我想振动很多次..这不是我的要求,我希望whwn用户第二次启动应用程序此案例执行。。但是我的手机没有震动。