【代码笔记】调用系统震动和声音
2016-01-25 08:38
357 查看
代码:
RootViewController.m
RootViewController.m
#import "RootViewController.h" #import <AudioToolbox/AudioToolbox.h> @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"RootViewController"; //这个震动不震动,有没有声音是和手机的设置一样的。 //调用系统震动 [self getChatMessageGoToShake]; //调用系统声音 [self getChatMessageGoToSound]; } #pragma -mark -调用系统震动 - (void)getChatMessageGoToShake { //调用系统震动 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } #pragma -mark -调用系统声音 - (void)getChatMessageGoToSound { //调用系统声音 NSString *path = [NSString stringWithFormat:@"/System/Library/Audio/UISounds/%@.%@",@"sms-received3",@"caf"]; if (path) { SystemSoundID sd; OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&sd); //获取声音的时候出现错误 if (error != kAudioServicesNoError) { NSLog(@"----调用系统声音出错----"); sd = 0; } AudioServicesPlaySystemSound(sd); } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
相关文章推荐
- 【代码笔记】调用系统震动和声音
- JAVA的Socket编程初步
- 排序算法代码 早年练习题 冒泡 归并 快速
- Leetcode 39 - Combination Sum
- 当你选择编程语言时你在选择什么
- Java 线程
- 44. Wildcard Matching leetcode Python 2016 new season
- Leetcode 38 - Count and Say
- C#中数组,ArrayList和List三者的区别
- C#的ArrayList集合的使用
- C#返回arraylist集合长度的方法是什么?C#ArrayList重复数据删除
- java图形
- java图形
- 43. Multiply Strings leetcode python 2016 new season
- C++链表
- Java 包
- Python常用函数
- Python如何进行cross validation training
- Python/Keras如何将给定的数据集打乱
- Python-装饰器以及对带有参数的装饰器的理解