0

如何在定位速度大于 20 时播放音频播放器,计数时间开始 5 秒,当突然定位速度(速度从 20 t0 0 下降)等于零时播放音频播放器。我尝试了这个但没有发生任何事情请帮助我。这里是我的代码

int i;

- (void)locationUpdate:(CLLocation *)location{
    speedLabel.text = [NSString stringWithFormat:@"%.2fmph",[location speed]*2.236936284];

    if (location.speed >= 10)
    {
        [self performSelector:@selector(doThis) withObject:nil afterDelay:5];
        if (location.speed ==0) {
            [audioPlayer play];
        }
    }
}

-(void)doThis{
    if(i %5 == 0)     
    {
        [CLController.locMgr startUpdatingLocation];
    }
}
4

1 回答 1

0

您的条件检查不会播放音频。按照给定的方式进行更改,

int i;

- (void)locationUpdate:(CLLocation *)location{
    speedLabel.text = [NSString stringWithFormat:@"%.2fmph",[location speed]*2.236936284];

    if (location.speed >= 10)
    {
        [self performSelector:@selector(doThis) withObject:nil afterDelay:5];

    }
    else if (location.speed ==0) {
        [audioPlayer play];
    }

}

-(void)doThis{
if(i %5 == 0)     
{
    [CLController.locMgr startUpdatingLocation];
}
}
于 2013-05-20T04:36:48.290 回答