gpt4 book ai didi

ios - 由于未捕获的异常 'NSInternalInconsistencyException' 终止应用程序,原因 : 'Only run on the main thread!'

转载 作者:搜寻专家 更新时间:2023-11-01 07:30:02 25 4
gpt4 key购买 nike

我正在跟踪我的应用中的崩溃。这个特殊的崩溃给我错误“由于未捕获的异常'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.")
}
})

最佳答案

错误信息是Only run on the main thread!。原因是您在后台线程中更新了 UI (testObject.saveInBackgroundWithBlock ({ (success, error) -> Void in)。检查您的更新 UI 任务,例如隐藏按钮、停止动画、导航.. ., 并将其移动到主线程。

dispatch_async(dispatch_get_main_queue(), ^{
/* Your UI code */
});

关于ios - 由于未捕获的异常 'NSInternalInconsistencyException' 终止应用程序,原因 : 'Only run on the main thread!' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33138331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com