ios开发之打开系统的声音

在iOS应用中,有时需要调用系统声音或震动。通过引入AudioToolbox.framework库和相关代码,可以实现这一功能。文章介绍了如何添加库、导入头文件,并提供了播放系统声音的代码示例,包括获取文件路径、创建SystemSoundID及播放音频。
摘要由CSDN通过智能技术生成

在自己的程序中,有的时候需要打开系统声音、震动之类的!下面这个就可能会帮助你解决相关问题:

首先在自己的工程中添加AudioToolbox.framework库,在.m文件中添加头文件:#import <AudioToolbox/AudioToolbox.h>


然后在需要打开声音的地方添加代码:AudioServicesPlaySystemSound(audioID);

其中audioID就是你需要打开系统声音的id号:附上系统对应提示音对照表:

There are some predefined system sounds, for the system sound ID in the range 1000 to 2000 (decimal), as shown below (from 2.0 to 5.0 beta). The system sounds are all stored in/System/Library/Audio/UISounds/.


Sound ID File name (iPhone) File name (iPod Touch) Category Note
1000 new-mail.caf new-mail.caf MailReceived  
1001 mail-sent.caf mail-sent.caf MailSent  
1002 Voicemail.caf Voicemail.caf VoicemailReceived  
1003 ReceivedMessage.caf ReceivedMessage.caf SMSReceived  
1004 SentMessage.caf SentMessage.caf SMSSent  
1005 alarm.caf sq_alarm.caf CalendarAlert  
1006 low_power.caf low_power.caf LowPower  
1007 sms-received1.caf sms-received1.caf SMSReceived_Alert  
1008 sms-received2.caf sms-received2.caf SMSReceived_Alert  
1009 sms-received3.caf sms-received3.caf SMSReceived_Alert  
1010 sms-received4.caf sms-received4.caf SMSReceived_Alert  
1011 - - SMSReceived_Vibrate  
1012 sms-received1.caf sms-received1.caf SMSReceived_Alert  
1013 sms-received5.caf sms-received5.caf SMSReceived_Alert  
1014 sms-received6.caf sms-received6.caf SMSReceived_Alert  
1015 Voicemail.caf Voicemail.caf - Available since 2.1
1016 tweet_sent.caf tweet_sent.caf SMSSent Available since 5.0
1020 Anticipate.caf Anticipate.caf SMSReceived_Alert Available since 4.2
1021 Bloom.caf Bloom.caf SMSReceived_Alert Available since 4.2
1022 Calypso.caf Calypso.caf SMSReceived_Alert Available since 4.2
1023 Choo_Choo.caf Choo_Choo.caf SMSReceived_Alert Available since 4.2
1024 Descent.caf Descent.caf SMSReceived_Alert Available since 4.2
1025 Fanfare.caf Fanfare.caf SMSReceived_Alert Available since 4.2
1026 Ladder.caf
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值