因此,我擁有的代碼通過一個按鈕連接到故事板。該按鈕可以發出一種叫做笑聲的效果。但是當按下按鈕時。應用程序崩潰,並將這個錯誤「主題1:信號SIGABRTXcode Swift - 按下按鈕時應用程序崩潰
//
// ViewController.swift
// LaLaLaughing
//
// Created by MightyShin on 5/16/16.
// Copyright © 2016 Reverze. All rights reserved.
//
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func LaughSound(sender: AnyObject) {
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Laughing", ofType: "mp3")!)
do {
// Preperation
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch _ {
}
// Play the sound
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound)
} catch _{
}
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}
顯示完整的stracktrace。 – trojanfoe
什麼是stracktrace? – RapidReverse
@RapidReverse複製和粘貼Xcode調試器在應用程序崩潰時顯示的所有內容 –