objective-c - Objective C 中 AudioToolbox 的引用错误

标签 objective-c

我在尝试播放一些 wav 文件的简单 Roulett 应用程序中遇到以下错误。我不确定错误是什么意思,因为代码中没有出现警告标志,而且我已经导入了

这里是错误:

Undefined symbols:
"_AudioServicesCreateSystemSoundID", referenced from: -[CustomPickerViewController playWinSound] in CustomPickerViewController.o -[CustomPickerViewController spin:] in CustomPickerViewController.o "_AudioServicesPlaySystemSound", referenced from: -[CustomPickerViewController playWinSound] in CustomPickerViewController.o -[CustomPickerViewController spin:] in CustomPickerViewController.o ld: symbol(s) not found collect2: ld returned 1 exit status
"_AudioServicesCreateSystemSoundID", referenced from: -[CustomPickerViewController playWinSound] in CustomPickerViewController.o -[CustomPickerViewController spin:] in CustomPickerViewController.o "_AudioServicesPlaySystemSound", referenced from: -[CustomPickerViewController playWinSound] in CustomPickerViewController.o -[CustomPickerViewController spin:] in CustomPickerViewController.o ld: symbol(s) not found collect2: ld returned 1 exit status

代码如下:

#import "CustomPickerViewController.h"
#import <AudioToolbox/AudioToolbox.h>

@implementation CustomPickerViewController
@synthesize picker;
@synthesize winLabel;
@synthesize column1;
@synthesize column2;
@synthesize column3;
@synthesize column4;
@synthesize column5;
@synthesize button;

- (void)showButton
{
    button.hidden = NO;
}

-(void)playWinSound
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"win" ofType:@"wav"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
    AudioServicesPlaySystemSound (soundID);     
    winLabel.text = @"WIN!";
    [self performSelector:@selector(showButton) withObject:nil afterDelay:1.5];
}



-(IBAction)spin:(id)sender
{
    BOOL win = NO;
    int numInRow = 1;
    int lastVal = -1;
    for (int i = 0; i < 5; i++)
    {
        int newValue =random() % [self.column1 count];

        if (newValue == lastVal)
            numInRow++;
        else
            numInRow = 1;

        lastVal = newValue;
        [picker selectRow:newValue inComponent:i animated: YES];
        [picker reloadComponent:i];
        if (numInRow >= 3)
            win = YES;
    }

    button.hidden = YES;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"crunch"ofType:@"wav"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:path], &soundID);
    AudioServicesPlaySystemSound(soundID);

    if (win)
        [self performSelector:@selector(playWinSound) withObject: nil afterDelay: .5];
    else 
        [self performSelector:@selector(showButton) withObject: nil afterDelay: .5];

    winLabel.text = @"";
}

最佳答案

找到了。意识到我没有在 XCode 中导入 Framework AudioToolbox.Framework。 :)

关于objective-c - Objective C 中 AudioToolbox 的引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/683940/

相关文章:

ios - 如何在obj-c中深度复制int

objective-c - 从自定义单元格返回 NSIndexPath ? (UITableView)

IOS 如何使用 nsscanner 类查找完整的 rss 提要链接

objective-c - 为表格 View (UITableView)绘制自定义单元格,更改颜色和分隔符颜色和宽度

ios - CoreData 和预加载 sqlite

objective-c - 为什么在分配一个 View 并将其添加到另一个 View 后,保留计数变为 3?

objective-c - 将 (void *) 转换为 (SInt16 *) 到 Swift

ios - 即使在 app 为 "Deleted"之后,有没有办法跟踪耗时?

ios - 如何在 IOS 中删除没有动画的 UITableView 中的行

ios - 上传 PFFile 和 PFObject 的区别