如何播放简单的系统声音

use*_*026 3 audio objective-c ios

我只需要播放一个简单的声音,我有发送消息的应用程序,我需要在发送消息时播放"消息发送"系统声音.

Rya*_*los 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];
Run Code Online (Sandbox Code Playgroud)