Ios 如何在没有Cocos2D的情况下在现有应用程序中实现声音

Ios 如何在没有Cocos2D的情况下在现有应用程序中实现声音,ios,user-interface,sdk,audio,Ios,User Interface,Sdk,Audio,例如,在iOS SDK下载页面上,有示例代码;我正在使用计算器应用程序(iPhoneUnitTests)。我想知道是否有可能添加声音的按钮按下的应用程序,已经建成,很容易 实际上播放短音非常简单,比如按钮音。下面是一个简单的例子 您必须链接AudioToolbox.framework二进制文件 SoundExampleViewController.h #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h>

例如,在iOS SDK下载页面上,有示例代码;我正在使用计算器应用程序(iPhoneUnitTests)。我想知道是否有可能添加声音的按钮按下的应用程序,已经建成,很容易

实际上播放短音非常简单,比如按钮音。下面是一个简单的例子

您必须链接AudioToolbox.framework二进制文件

SoundExampleViewController.h

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface SoundExampleViewController : UIViewController{
    SystemSoundID mySoundID;
}
@end

然后要播放,只需调用:
AudioServicesPlaySystemSound(mySoundID)

修复了AVAudioPlayer的内存泄漏问题,谢谢!
#import "SoundExampleViewController.h"
@implementation SoundExampleViewController
- (void)viewDidLoad{
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"SoundFileName" ofType:@"wav"]; 
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&mySoundID);
}
- (void)viewDidUnload{
    [super viewDidUnload];
    AudioServicesDisposeSystemSoundID(mySoundID);
}
@end