0
時12小時後,我得到的墜毀報告18次大約一種的HTTPRequest方法。iOS應用崩潰有時處理的HTTPRequest(JSON)
此方法用於從服務器加載歌曲信息,例如歌曲標題,解釋。
的崩潰報告來自Fabric.io,但我不能unterstand非常好,這是一種約的NSOperation和線程....
我的問題是,什麼也使崩潰?以及如何改善此功能loadMetadata()
?
這是崩潰報告的截圖,爲什麼在線0?
這是其中的HTTPRequest的代碼從服務器獲取
func loadMetadata() {
if self.hasConnectivity() {
let url = NSURL(string: "http://sites.exampleserver.de/files/playlist/streamdaten_json.txt")
let request = NSMutableURLRequest(URL:url!)
let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
sessionConfiguration.requestCachePolicy = .ReloadIgnoringLocalCacheData
let session = NSURLSession(configuration: sessionConfiguration, delegate: nil, delegateQueue: nil)
session.dataTaskWithRequest(request) { (data, response, error) -> Void in
let httpResponse = response as! NSHTTPURLResponse
let statusCode = httpResponse.statusCode
if (statusCode == 200) {
do{
let json = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments) as? NSDictionary
print(json)
var title : String
var interpret : String
switch (self.channels.channel) {
case 0:
title = json?.objectForKey("Titel_Live") as! String
interpret = json?.objectForKey("Interpret_Live") as! String
case 1:
title = json?.objectForKey("Titel_InTheMix") as! String
interpret = json?.objectForKey("Interpret_InTheMix") as! String
default:
title = ""
interpret = ""
}
if self.lastTitle != title || self.lastInterpret != interpret || self.lastChannel != self.channels.channel {
if title.lengthWithoutWhitespace() < 1 && interpret.lengthWithoutWhitespace() < 1 {
self.songTitle = self.channels.currentDefaultArtist
self.albumTitle = self.channels.currentDefaultTitle
} else {
if self.lastTitle != title { // title has changed
self.albumTitle = title.lengthWithoutWhitespace() > 1 ? title : self.channels.currentDefaultArtist
}
if self.lastInterpret != interpret || self.lastChannel != self.channels.channel { // interpret has changed
self.songTitle = interpret.lengthWithoutWhitespace() > 1 ? interpret : self.channels.currentDefaultArtist
}
}
}
self.lastTitle = title
self.lastInterpret = interpret
self.lastChannel = self.channels.channel
// Test currentInfo
self.metaDataHandler.setInfo(artist: self.songTitle, title: self.albumTitle)
}catch {
print("Error with Json: \(error)")
}
}
}.resume()
}
}
感謝了很多!我已經瞭解了關於選擇,現在明白了問題的出處。 – shilei365