首先要build phases->link binary with libraries->加入audiotoolbox.framework
接著在.h 加入
#import <AudioToolbox/AudioToolbox.h>
CFBundleRef mainbundle = CFBundleGetMainBundle();
CFBundleRef mainbundle = CFBundleGetMainBundle();
CFURLRef soundfileurl;
soundfileurl = CFBundleCopyResourceURL(mainbundle, (CFStringRef)@"water",CFSTR("wav"),NULL);
UInt32 soundid;
AudioServicesCreateSystemSoundID(soundfileurl, &soundid);
AudioServicesPlaySystemSound(soundid); //播放音效
water.wav 是音效檔名稱
此行是當記憶體低落的時候把音效關閉.
AudioServicesDisposeSystemSoundID(soundid);