1.首先在项目文件中添加用到的系统框架 #import <AudioToolbox/AudioToolbox.h>
2.调用震动代码:AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
3.1系统声音:AudioServicesPlaySystemSound(1007); 其中1007是系统声音的编号。
3.2用户音效:
NSString *path = [[NSBundle mainBundle] pathForResource:@"XiaoPingGuo" ofType:@"aiff"];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)(filePath), &soundID);
AudioServicesPlaySystemSound(soundID);
//声音停止:AudioServicesDisposeSystemSoundID(soundID);
网友评论