1.播放短声音
SystemSoundID shake_sound_male_id = 0;
NSString *thesoundFilePath = [[NSBundle mainBundle] pathForResource:@"ReceivedMessage" ofType:@"caf"]; //音乐文件路径
CFURLRef thesoundURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:thesoundFilePath]);
AudioServicesCreateSystemSoundID(thesoundURL, &shake_sound_male_id);
AudioServicesPlaySystemSound(shake_sound_male_id);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//播放震动
2.播放系统声音
AudioServicesPlaySystemSound(1004); //更换播放系统的声音 id值可以百度查询
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//震动
3.在主线程中刷新UI
dispatch_async(dispatch_get_main_queue(), ^{
_lbName=@"Name";
});
4.函数延时执行
//这样实现延时调用是错误的,playSound是不会被调用的 可以在主线程调用
dispatch_async(dispatch_get_global_queue(2, 0), ^{
[self performSelector:@selector(playSound) withObject:nil afterDelay:0.5f];//NSTimer 也需要注意这点
});
5.一个函数短时间多次触发,希望函数里摸个代码段只执行一次
//这个是抄的 原地址http://www.cocoachina.com/bbs/read.php?tid=193276
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(playSound) object:nil];
[self performSelector:@selector(playSound) withObject:nil afterDelay:0.5f];
以后要多记录一下咯,很短以为能记住,过段时间又忘了,又要打开以前的项目来看,自己记忆力真的不行,以后就多
记录下。