技术开发 频道

新手必读:iPhone SDK示例代码解析

  震动和声音播放

  下面介绍的就是如何让手机震动(注意:在simulator里面不支持震动,但是他可以在真机上支持。)

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

 

  Sound will work in the Simulator, however some sound (such as looped) has been reported as not working in Simulator or even altogether depending on the audio format. Note there are specific filetypes that must be used (.wav in this example).

SystemSoundID pmph;
id sndpath
= [[NSBundle mainBundle]
    pathForResource:@
"mySound"
    ofType:@
"wav"
    inDirectory:@
"/"];
CFURLRef baseURL
= (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath];
AudioServicesCreateSystemSoundID (baseURL,
&pmph);
AudioServicesPlaySystemSound(pmph);    
[baseURL release];
0
相关文章