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

标签 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

最佳答案

包括触发计时器:

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

关于ios - 每五秒发出一次声音循环警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56403673/

相关文章:

ios - UiCollectionView 必须使用非 nil 布局参数初始化 Swift 3

objective-c - 框架和 XIB

ios - 如何在 Xcode 8.3 中导入私有(private)框架而不出现 "Undefined symbols for architecture arm64"

ios - 从桌面或服务器以编程方式访问(您自己的)iCloud 数据?

ios - 如何使用 OCMock 模拟服务

ios - 无法在发布架构中运行 iOS React Native 应用程序

ios - SDWebImage - 如何延长下载超时

objective-c - Objective C 中未定义选择器的警告如何工作?

objective-c - 我怎样才能拥有一个同时包含图像和文本的 UIBarButtonItem?

iphone - ipad/iphone 禁用退出按钮