iOS开发-震动及音频播放

1.首先在项目文件中添加用到的系统框架 #import

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);

你可能感兴趣的:(iOS开发-震动及音频播放)