Audio will play in iPhone simulator, but not on device
Basically, when a button on my app is touched, audio is played. Simple enough, and yet it fails to work on my actual device, but works well in the simulator. When the button is touched, this function is executed:
开发者_运维知识库- (IBAction)playButtonSound
{
SystemSoundID buttonSound;
NSURL *tapSound = [[NSBundle mainBundle] URLForResource: @"Button_Sound" withExtension: @"caf"];
CFURLRef buttonSoundURLRef = (CFURLRef) [tapSound retain];
AudioServicesCreateSystemSoundID (buttonSoundURLRef, &buttonSound);
AudioServicesPlaySystemSound(buttonSound);
[tapSound release];
}
I'm still an iPhone newbie, so I'm not entirely sure what the cause of this is.
- Works on iPhone Simulator but not on device
Make sure you write the correct file names, iOS is case sensitive, simulator is not.
Do you have system sounds disabled on your device? As its name implies, AudioServicesPlaySystemSound
will normally not play if the user has system sounds disabled. There is a property kAudioServicesPropertyIsUISound
that is supposed to be able to be set to NO to disable this behavior.
精彩评论