iphone开发 播放短声音

在iphone开发中我们有时候需要播放短音提示用户的操作,iphone api提供了简单的播放短音类,具体实现方法如下

    //播放声音变量
    CFURLRef soundFileURLRef;
    SystemSoundID soundFileObject;
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, CFSTR("page"), CFSTR("aif"), NULL);
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);
    //播放声音
    AudioServicesPlaySystemSound(soundFileObject);
    //销毁变量释放内存
    AudioServicesDisposeSystemSoundID(soundFileObject);
    CFRelease(soundFileURLRef);
原文地址:https://www.cnblogs.com/fighter/p/2090652.html