引入头文件:
#import <AudioToolbox/AudioToolbox.h>
想用自己的音频文件创建系统声音来播放的同学可以参考如下代码。
//Get the filename of the sound file:
NSString *musicFilePath = [[NSBundlemainBundle]pathForResource:@"shake_match"ofType:@"mp3"];
//Get a URL for the sound file
NSURL * musicURL= [[NSURLalloc] initFileURLWithPath:musicFilePath];
soundID = 1000001;
//Use audio sevices to create the sound
AudioServicesCreateSystemSoundID(( CFURLRef)musicURL, &soundID);
//Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);
这里的soundID在头文件(.h)里定义
SystemSoundID soundID;
注册时只需要给soundID初始化一个数值
AudioServicesCreateSystemSoundID(( CFURLRef)musicURL, &soundID);
顺便附上系统提示音对应的列表
http://iphonedevwiki.net/index.php/AudioServices
AudioServicesPlaySystemSound(1100);
@追风 2012/12/13