我可以将声音添加到Xcode';什么是故事板模式?

我可以将声音添加到Xcode';什么是故事板模式?,xcode,audio,storyboard,Xcode,Audio,Storyboard,我刚开始为iOS创建应用程序,现在使用的是故事板模式。我想知道如何添加声音。此外,它是否需要编码?您可以使用它播放简单的声音。它使用AVFoundation框架,这将要求您将AVFoundation添加到项目中,并使用#import - (IBAction) myPlayAction { AVAudioPlayer *data; NSString *name = [[NSString alloc] initWithFormat:@"SoundName"]; NSStrin

我刚开始为iOS创建应用程序,现在使用的是故事板模式。我想知道如何添加声音。此外,它是否需要编码?

您可以使用它播放简单的声音。它使用
AVFoundation
框架,这将要求您将AVFoundation添加到项目中,并使用
#import

- (IBAction) myPlayAction {
    AVAudioPlayer *data;
    NSString *name = [[NSString alloc] initWithFormat:@"SoundName"];
    NSString *source = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
    if (data) {
        [data stop];
        data = nil;
    }
    data=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: source] error:NULL];
    data.delegate = self;
    [data prepareToPlay];
    [data play];
}