我有一个奇怪的行为,我的应用程序崩溃后回到以前的视图控制器。我有一个显示配置文件控制器,然后我去编辑配置文件控制器。我录制音频文件有,然后再回到我以前的观点控制器1秒后,应用程序崩溃,没有错误只是一个DispatchSourceTimer崩溃应用程序没有错误在segue
线程1:EXC_BREAKPOINT(代码= 1,子码= 0x1026eb43c)
我使用DispatchSourceTimer
要能在视图中添加计数器,同时记录录制的声音和我初始化的全局变量是这样的:
var nonObservalePropertyUpdateTimes:DispatchSourceTimer = DispatchSource.makeTimerSource(flags: [], queue: DispatchQueue.main)
这里将使用称为一个Singltone类我是怎么做的记录210:
@IBAction func micButtonTapped(_ sender: UIButton) {
if recButtonIsChecked {
if AudioManager.shared.record(fileName: "recbio") {
sender.setBackgroundImage(UIImage(), for: .normal)
sender.setImage(#imageLiteral(resourceName: "pauseProfileButton"), for: .normal)
playRecordButton.setBackgroundImage(#imageLiteral(resourceName: "editProfilePlay"), for: .normal)
recordVoiceLabel.isHidden = true
recButtonIsChecked = false
secondsLabel.isHidden = false
nonObservalePropertyUpdateTimes.resume()
}
nonObservalePropertyUpdateTimes.setEventHandler {[weak self] in
self?.secondsLabel.text = String(describing: AudioManager.shared.countDownTimer)
}
nonObservalePropertyUpdateTimes.schedule(deadline: DispatchTime.now(), repeating: DispatchTimeInterval.milliseconds(100))
} else {
sender.setBackgroundImage(#imageLiteral(resourceName: "editProfileMicButton"), for: .normal)
sender.setImage(UIImage(), for: .normal)
recButtonIsChecked = true
stopRecording()
}
}
什么,我相信是有一些错误发生在导致此崩溃DispatchQueue因为当我从编辑个人资料视图控制器删除nonObservalePropertyUpdateTimes
对象时,我回Segue公司的应用程序没有崩溃我的个人资料视图控制器。
所以我想这样做,但它并没有帮助:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
nonObservalePropertyUpdateTimes.suspend()
nonObservalePropertyUpdateTimes.cancel()
}
或者,也许有一种方法来deinit
此Dispatch对象。我真的不知道什么是错的,该怎么办。我甚至没有正确的错误信息。
我开始怀疑'AudioManager.shared.countDownTimer'。目前还不清楚该代码中的内容。但是你可以通过删除它来探索这个问题,并将文本设置为Date()或类似的东西。 –
countDownTimer是一个Int变量,以15开头,然后我倒数 - 每1秒钟在AudioManager类中使用一个定时器。录音部分工作正常,正如我所说,一切都很好。问题是在派送,因为当我没有派遣记录“当然我的标签没有被更新”,但它不会崩溃时,我回到我的主要配置文件视图控制器。因为我初始化了DispatchSourceTimer的一个实例。 –
我接下来换出一个'NSTimer'的'DispatchSourceTimer'。这将告诉你如果问题出现在'DispatchSource'中。 –