2012-05-14 65 views

回答

6

看看AudioServicesPlayAlertSound這是我如何發揮系統滴答聲。儘可能簡單。只需找到您想播放的聲音的名稱即可。

別忘了導入#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]; 
+0

我需要包括聲音文件,或者它已經存在於系統中? – user836026

+1

如果一個系統文件,那麼你就不需要。像我一樣在Tock中,我只是從所有設備上的UIKit包中引用它,所以如果你真的找到發送消息的文件,它不僅僅是一個文件專用於mail.app,而是整個系統,那麼你將能夠參考它不包括它。 –