开发笔记 - 自定义推送声音

来源:互联网 发布:建筑设计制图软件 编辑:程序博客网 时间:2024/06/06 20:46

简单播放自定义声音

  • 播放简单声音,需要导入系统 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); // 1304 为系统中某个声音ID    }}

极光推送自定义声音

  • 后台推送时,有个sound参数可填,默认为default,即系统默认推送声音。如果自定义,只需你把音乐文件添加到工程中。iOS播放声音是有格式要求的,自己Google一下就知道支持哪些了。最后在sound这个参数中填入声音文件名且带上后缀名。
0 1
原创粉丝点击