每五秒钟发出一次声音循环警报

时间:2019-06-01 03:36:29

标签: ios objective-c jailbreak tweak

我正在尝试每五秒钟编写一个简单的循环声音警报

我如何添加它

为Cydia进行调整

Tweak.xm模板

     if (lowenabled) {
      if ([batString isEqualToString:lowbatPercent_String]) {
        if (lowplayer) {
          return;
        }

        if (lowsound == 0)
          soundFilePath = [NSString stringWithFormat:@"%@/Super Mario.mp3", bundlePrefix];
        else if (lowsound == 1)
          soundFilePath = [NSString stringWithFormat:@"%@/Super Mario 1.mp3", bundlePrefix];

        soundFileURL = [NSURL fileURLWithPath:soundFilePath];

        lowplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
        lowplayer.numberOfLoops = 3;
        [lowplayer play];
      } else {
        if (lowplayer) {
          lowplayer = nil;
        }
      }
    }
}
%end

1 个答案:

答案 0 :(得分:0)

包含到触发计时器:

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(playSound:) userInfo:nil repeats:YES];
[timer fire];

将方法放在同一类中:

- (void)playSound {
 // the code you included here that plays the sound
}

Docs for NSTimer's fire method