2017-07-23 29 views
0

發生這種情況時,我正在保存視頻,我也試圖segue到另一個視圖控制器。我不知道爲什麼應用程序崩潰這裏線程8:信號SIGABRT當執行一個segue時

func finalExportCompletion(_ session: AVAssetExportSession) { 
    PhotoManager().saveVideoToUserLibrary(fileUrl: session.outputURL!) { (success, error) in 
     if success { 
      ProgressHUD.showSuccess("Video Saved", interaction: true) 
      self.finalVideo = session.outputURL! 
      //FileManager.default.clearTmpDirectory() 
      self.clipsCollectionView.reloadData() 
     } else { 
      ProgressHUD.show(error?.localizedDescription) 
     } 
     self.performSegue(withIdentifier: "toPostVideoViewController", sender: nil) 
    } 
} 
+0

session.outputURL你的代碼!在我看來是罪魁禍首。使其可選,並安全地解開它。 –

+0

不要在後臺線程上執行UI更新。 – rmaddy

+0

我試着安全地使用 來解包它if let video = session.outputURL! { 它給了我錯誤:條件綁定的初始值設定項必須有可選類型,而不是'URL' –

回答

0

你的崩潰是頒發給在UI修改,而你是在後臺線程,如說你的崩潰日誌,並在他的評論@rmaddy,THREAD 8是一個後臺線程,您需要執行所有的UI操作中Thread 1這是「主線程」必須修改這樣

func finalExportCompletion(_ session: AVAssetExportSession) { 
    PhotoManager().saveVideoToUserLibrary(fileUrl: session.outputURL!) { (success, error) in 
     DispatchQueue.main.async{ 
      if success { 
       ProgressHUD.showSuccess("Video Saved", interaction: true) 
       self.finalVideo = session.outputURL! 
       //FileManager.default.clearTmpDirectory() 
       self.clipsCollectionView.reloadData() 
      } else { 
       ProgressHUD.show(error?.localizedDescription) 
      } 
      //I don't know if you anyway want to go to "toPostVideoViewController" this you need to do it also in main thread 
      self.performSegue(withIdentifier: "toPostVideoViewController", sender: nil) 
     } 
    } 
} 
+0

在'saveVideoToUserLibrary'回調關閉中使用'DispatchQueue.main.async'會更簡單一些,因爲其中的所有內容都需要在主隊列上運行。 – rmaddy

+0

謝謝@rmaddy你是對的! –

+0

謝謝你們。我感謝幫助! –