简单播放自定义声音
- 播放简单声音,需要导入系统 AudioToolbox/AudioToolbox.h
#pragma mark ---
- (void)playSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Call" ofType:@"wav"];
SystemSoundID soundID;
if (path)
{
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&soundID);
AudioServicesPlaySystemSound(soundID);
}
else
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(1304);
}
}
极光推送自定义声音
- 后台推送时,有个sound参数可填,默认为default,即系统默认推送声音。如果自定义,只需你把音乐文件添加到工程中。iOS播放声音是有格式要求的,自己Google一下就知道支持哪些了。最后在sound这个参数中填入声音文件名且带上后缀名。