3

I just need to play a simple sound, I have app that send messages, and I need to play "message sent" system sound when message get sent.

4

2 回答 2

7

这就是我播放系统滴答声的方式。尽可能简单。只需找到您要播放的声音的名称即可。

不要忘记导入#import <AVFoundation/AVFoundation.h>
并添加AVFoundation.framework目标的构建阶段。

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"]] error:NULL];
[audioPlayer play];
于 2012-05-14T20:55:06.347 回答
3

查看AudioServicesPlayAlertSoundiOS系统声音服务参考

于 2012-05-14T20:54:01.183 回答