这是我的代码,正在播放声音,但是在我更新到xcode 6.1之后,我得到了这个错误
调用中的额外参数'contentsOfURL‘
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sound", ofType: "aiff")!)
//println(alertSound);
// Removed deprecated use of AVAudioSessionDelegate protocol
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error:NSError?;
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error); // the error
audioPlayer.prepareToPlay();如何修复错误和xcode以停止显示它
发布于 2014-11-07 19:02:25
在这一行:
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)问题是alertSound现在是可选的,因为NSURL(fileURLWithPath:)可以返回零。你需要拆开它:
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound!, error: &error)这将允许您的代码编译。但是,在执行此操作之前,最好显式检查alertSound是否为零!如果它是零,直接展开它将导致崩溃。
https://stackoverflow.com/questions/26566962
复制相似问题