正确释放系统声音ID



我使用AudioToolboxSystemSoundID来加载和播放声音。

这是我的viewDidLoad方法中的代码:

NSString *swipeFilePath = [[NSBundle mainBundle] pathForResource:@"swipe" ofType:@"caf"];
NSURL *swipeFileURL = [NSURL fileURLWithPath:swipeFilePath];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)swipeFileURL, &swipe);

每次我需要它播放时,我都会做以下操作:

AudioServicesPlaySystemSound(swipe);

我知道我必须自己释放它,因为它不是obj-c对象,但我不确定我做得是否正确。

我做了以下事情,只是它产生了一个错误:

- (void)dealloc {
AudioServiceDisposeSystemSoundID(swipe);
}

警告:函数"AudioServiceDisposeSystemSoundID"的隐式声明在C99中无效

释放声音的合适方式是什么?

函数名称为:

AudioServicesDisposeSystemSoundID
            ^

存在"s"售后服务

最新更新