虽然代码不长 但是还是分开总结 方便初学者学习
#import "ViewController.h"
/**
* 首先要导入头文件
*
* @param void <#void description#>
*
* @return <#return value description#>
*/
#import <AudioToolbox/AudioToolbox.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//播放系统的声音 后面的数值是苹果公司规定好的
//如果使用我们需要查看相关的文档 根据自己的需求使用
//这里要注意的是: 虽然代码很简短 但是可以完成我们想要使用的功能
//我们学习ios 开发应该慢慢的了解到越是看来比较高级的功能 越是简单
//几行代码就可以搞定 所以我们平常要多总结经验 虽然代码不长 但是功能可以实现
AudioServicesPlaySystemSound(1005);
//震动播放
AudioServicesPlayAlertSound(SystemSoundID inSystemSoundID);
//播放自定义声音
SystemSoundID soundID;
NSURL *url = [NSURL fileURLWithPath:[NSBundle mainBundle]pathForResource:@"xxx" ofType:@"xxx"];
//创建一个SoundID
//这里函数是C 语言的东西 大家要注意了
AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID);
//手机震动
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end