添加系統框架: #import <AudioToolbox/AudioToolbox.h> 調用震動代碼: AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 2.消息聲音 2.1 系統聲音 AudioServicesPlaySystemSound(1007); 其中1007是系統聲音的編號,其他的可用編號: iphone 系統鈴聲 2.2 用戶音效 //音效文件路徑 NSString *path = [[NSBundle mainBundle] pathForResource:@"message" ofType:@"wav"]; //組裝並播放音效 SystemSoundID soundID; NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); AudioServicesPlaySystemSound(soundID); //聲音停止 AudioServicesDisposeSystemSoundID(soundID);
