1
我正在跟蹤應用程序中的崩潰。這個特殊的崩潰給我錯誤「終止應用程序,由於未捕獲的異常'NSInternalInconsistencyException',原因:'只能在主線程上運行!'」。奇怪的是我似乎無法使用我的設備或模擬器重新創建崩潰,但在我的分析中,它表明這次崩潰發生了很多。由於未捕獲的異常'NSInternalInconsistencyException'而終止應用程序,原因:'僅在主線程上運行!'
這是代碼在碰撞發生的事情:
indicator.startAnimation()
let audioData = NSData(contentsOfURL: EditSongViewController.url.urlComplete!)
let dataImage: NSData = UIImageJPEGRepresentation(songImage.image!, 1.0)!
let imageFile = PFFile(name: "photo.jpg", data: dataImage)
let audioFile = PFFile(name: "song.mp4", data: audioData)
audioFile.saveInBackground()
imageFile.saveInBackground()
let testObject = PFObject(className: "PrivateSongs")
testObject["songFile"] = audioFile
testObject["image"] = imageFile
testObject["username"] = PFUser.currentUser().username
testObject["user"] = PFUser.currentUser()
testObject["title"] = self.songTitleText.text
testObject["songInfo"] = self.songInfoText.text
if RecordViewController.fileURL.songLyrics != nil {
testObject["lyrics"] = RecordViewController.fileURL.songLyrics
}
if (isPrivate == true) {
testObject["isPrivate"] = true
} else {
testObject["isPrivate"] = false
}
testObject.saveInBackgroundWithBlock ({ (success, error) -> Void in
if (success) {
if self.chartsSwitch.on {
let chart = PFObject(className: "Songs")
chart["artistName"] = PFUser.currentUser().username
chart["songFile"] = audioFile
chart["title"] = self.songTitleText.text
chart["picture"] = imageFile
chart["user"] = PFUser.currentUser()
chart["likes"] = 0
if RecordViewController.fileURL.songLyrics != nil {
chart["lyrics"] = RecordViewController.fileURL.songLyrics
}
chart.saveInBackground()
}
PostViewControler.share.shareUrl = audioFile.url!
self.postButton.hidden = true
self.addPictureButton.hidden = true
self.indicator.stopAnimation(false, completion: nil)
self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("ShareViewController") , animated: true)
} else {
self.indicator.stopAnimation(false, completion: nil)
self.helper.showErrorAlert("Couldn't save your song please try again.")
}
})
好的,這是我想,但我想知道爲什麼我似乎無法觸發崩潰,但在我的崩潰分析中,這經常發生。我正在做與用戶完全相同的事情,但該應用不會爲我崩潰。 – learningthings
我想它應該延遲更新你的用戶界面,因爲你在後臺線程中執行更新 – t4nhpt