我有一個奇怪的行爲,我的應用程序崩潰後回到以前的視圖控制器。我有一個顯示配置文件控制器,然後我去編輯配置文件控制器。我錄製音頻文件有,然後再回到我以前的觀點控制器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'中。 –