所以我所拥有的代码链接到一个带有按钮的故事板。该按钮假设发出一种名为Laughing的声音效果。但按下按钮时。应用程序崩溃并发送此错误"线程1:信号SIGABRT
//
// 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()
}
}
答案 0 :(得分:1)
Sigabrt通常关注连接。检查所有插座和操作。如果您创建了一个插座然后将其类型更改为textfield,或者将其名称(例如nameDoctorLabel)更改为doctorNameLabel,则可能会出现问题。
您可能还手动编写了IBoutlets和IbActions,忘记将它们与故事板中各自的对象链接。
同时检查IBAction左侧是否有填充的灰点。
检查连接检查器中的连接。