2017-10-21 185 views
0

我有一个奇怪的行为,我的应用程序崩溃后回到以前的视图控制器。我有一个显示配置文件控制器,然后我去编辑配置文件控制器。我录制音频文件有,然后再回到我以前的观点控制器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对象。我真的不知道什么是错的,该怎么办。我甚至没有正确的错误信息。

+0

我开始怀疑'AudioManager.shared.countDownTimer'。目前还不清楚该代码中的内容。但是你可以通过删除它来探索这个问题,并将文本设置为Date()或类似的东西。 –

+0

countDownTimer是一个Int变量,以15开头,然后我倒数 - 每1秒钟在AudioManager类中使用一个定时器。录音部分工作正常,正如我所说,一切都很好。问题是在派送,因为当我没有派遣记录“当然我的标签没有被更新”,但它不会崩溃时,我回到我的主要配置文件视图控制器。因为我初始化了DispatchSourceTimer的一个实例。 –

+0

我接下来换出一个'NSTimer'的'DispatchSourceTimer'。这将告诉你如果问题出现在'DispatchSource'中。 –

回答

0

确保主线程中运行的UI活动:

DispatchQueue.main.async { 
self?.secondsLabel.text = String(describing: AudioManager.shared.countDownTimer) 

} 
+0

无关。如果您阅读我在问题中添加的DispatchSourceTimer对象初始化代码,您将发现我正在主队列上进行调度。 –

1

感谢每一个机构谁试图帮助特别罗布。我只是通过这种方式取消了DispatchSourceTimer的初始化,并且它工作并且不再崩溃。

deinit { 
    nonObservalePropertyUpdateTimes.resume() 
} 
相关问题