我将我的项目转换为 ARC。Xcode 从示例中更改了代码中的这一行
soundFileURLRef = (CFURLRef) [tapSound retain];
至
soundFileURLRef = (__bridge CFURLRef) tapSound;
但没有声音播放。怎么了?
- (IBAction)buttonTapped:(UIButton *)sender {
// Create the URL for the source audio file. The URLForResource:withExtension: method is new in iOS 4.0
NSURL *tapSound = [[NSBundle mainBundle] URLForResource: @"abide" withExtension: @"aif"];
CFURLRef soundFileURLRef;
SystemSoundID soundFileObject;
// Store the URL as a CFURLRef instance
soundFileURLRef = (__bridge CFURLRef) tapSound; // I think this line is wrong
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (
soundFileURLRef,
&soundFileObject
);
AudioServicesPlaySystemSound (soundFileObject);
}