Objective C 中 AudioToolbox 的引用错误

2024-01-10

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

这是错误:

未定义的符号:
“_AudioServicesCreateSystemSoundID”, 参考自: -[CustomPickerViewController playWinSound] 中 CustomPickerViewController.o -CustomPickerViewController.o 中的[CustomPickerViewController spin:] “_AudioServicesPlaySystemSound”, 参考自: -[CustomPickerViewController playWinSound] 中 CustomPickerViewController.o -CustomPickerViewController.o 中的[CustomPickerViewController spin:] ld:未找到符号collect2:ld 返回 1 退出状态
“_AudioServicesCreateSystemSoundID”, 参考自: -[CustomPickerViewController playWinSound] 中 CustomPickerViewController.o -CustomPickerViewController.o 中的[CustomPickerViewController spin:] “_AudioServicesPlaySystemSound”, 参考自: -[CustomPickerViewController playWinSound] 中 CustomPickerViewController.o -CustomPickerViewController.o 中的[CustomPickerViewController spin:] ld:未找到符号collect2:ld 返回 1 退出状态

这是代码:

#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。 :)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Objective C 中 AudioToolbox 的引用错误 的相关文章

  • iPad 2 检测

    由于我没有 iPad 2 因此我需要知道调用 UIDevice currentDevice model 时它返回什么 我以为它只返回 iPad 但看来我错了 有人可以告诉我吗 Thanks 检查是否有带摄像头的 iPad BOOL isIP
  • 我如何在 viewDidLoad 中执行 UIView animateWithDuration ? IOS 7

    我在 viewDidAppear 中尝试这个 但我有一秒钟的延迟 我能做什么 在 viewDidLoad 中工作 void viewDidAppear BOOL animated fullRotation CABasicAnimation
  • 方向改变时重新定位控件

    我知道自动布局可用于在方向改变时使尺寸和位置保持一致 当方向改变时 是否可以完全改变布局 例如 请查看下面的纵向模式下简单登录屏幕的线框 现在 如果我旋转设备 我想完全重新定位控件 这种事情可以用自动布局来完成吗 如果没有 我该怎么办 谢谢
  • 如何以编程方式设置设备(UI)方向?

    希望屏幕 UI 上的所有内容都能够从横向左向右旋转 反之亦然 我该怎么做呢 这是私人的吗 我知道 BOOL shouldAutorotateToInterfaceOrientation UIInterfaceOrientation inte
  • 使用远程图像创建 MSSticker

    我正在尝试找出使用网络上托管的图像创建 MSStickers 的方法 我可以使用本地图像创建 MSStickers 例如 NSString imagePath NSBundle mainBundle pathForResource imag
  • NSString stringWithContentsOfFile 失败,错误代码似乎错误

    我正在尝试将文件加载到字符串中 这是我正在使用的代码 NSError error nil NSString fullPath NSBundle mainBundle pathForResource filename ofType html
  • 为什么在 init 方法中使用双括号,或者是 1 == (1)?

    评估某些含义时括号有什么作用 我在代码中遇到过这个问题 当检查某些内容并且他们使用 if some condition that returns 1 code 所以我的问题是 这是否正确 我认为它总是错误的 因为 1 不返回任何东西 编辑
  • locationOfTouch 和 numberOfTouches

    你好 我有这个识别器 设置为 2 次触摸 但它只返回一个 而不是两个 CGPoint void gestureLoad UIGestureRecognizer recognizer recognizer UITapGestureRecogn
  • 从一个模态视图无缝翻转到另一个模态视图,而不显示纯色背景

    我的 iPad 应用程序的 UI 如下 当我点击Settings按钮 我希望对话框水平翻转以显示设置对话框 我这个工作正常 但是 当对话翻转时会显示背景颜色 如你看到的 有什么办法可以让对话框翻转时不显示该颜色块吗 我希望它看起来更加无缝
  • 每 24 小时触发一次方法

    我正在尝试每天在给定时间触发一个方法 我尝试了一些方法 但我无法真正使其发挥作用 任何意见 将不胜感激 此外 如果无论应用程序是否打开它都会触发 那就更理想了 这可能吗 UI本地通知 http developer apple com lib
  • (Kiss)XML xpath 和默认命名空间

    我正在开发一个 iPhone 项目 需要解析一些 xml xml 可能包含也可能不包含默认名称空间 我需要知道如何解析 xml 以防它使用默认命名空间 由于我需要读取和写入 xml 因此我倾向于使用 KissXML 但我愿意接受建议 这是我
  • TableViewController 的 viewDidLoad 未触发

    我一直在关注这个tutorial http www appcoda com ios programming sidebar navigation menu 有一个滑出式菜单 我添加了一个 TableViewController 它将显示文章
  • 在实例化对象之前是否可以检查故事板中是否存在标识符?

    在我的代码中我有这一行 但我想知道是否有办法检查是否 一些控制器 在我将它与 一起使用之前就存在实例化ViewControllerWithIdentifier 方法 如果标识符不存在 则应用程序崩溃 如果没有好的方法 这并不是一个大问题 我
  • 像 TraceGL 一样分析 Objective C 中的代码路径?

    TraceGL 是一个非常简洁的项目 它允许 JS 程序员跟踪 Javascript 中的代码路径 它看起来像这样 我想为 Objective C 构建类似的东西 我知道运行时使跟踪方法调用变得相当容易 但是我如何跟踪控制流 例如 在上面的
  • ios - 如何声明静态变量? [复制]

    这个问题在这里已经有答案了 C 中声明的静态变量如下 private const string Host http 80dfgf7c22634nbbfb82339d46 cloudapp net private const string S
  • 在 iOS 中发送音频文件和 JSON 字符串

    我正在尝试将音频文件和 JSON 字符串发送到 PHP 服务器 使用以下代码将发送 JSON 但文件到达时为空 如果我将 JSON 块放在音频块下方 文件将完全到达 但 JSON 为空 有什么想法吗 void sendFile NSStri
  • 寻找可靠的方法来选择iPhone 13微距相机设备

    我正在使用 objc 开发一个应用程序 我必须选择 iPhone 13 Pro 和 13 Pro Max 中配备的新微距摄像头 目前 我在所有其他设备上选择我的相机 并剪掉此代码 AVCaptureDeviceDiscoverySessio
  • 如何在禁用状态下更改 UIButton 图像 alpha?

    我有一个带有图像的 UIButton 在其禁用状态下 该图像应具有 0 3 alpha UIButton button UIButton buttonWithType UIButtonTypeCustom UIImage arrowImag
  • 块如何捕获其封闭范围之外的变量?

    我知道 Objective C 块可以捕获并设置其封闭范围之外的变量值 它是如何做到的 它实际上相当简单 并在 Clang 的块实现规范中进行了描述 在 导入变量 http clang llvm org docs Block ABI App
  • 使用后台配置时 NSURLSessionDownloadTask 不断重试

    当涉及到缓慢的后端和使用后台配置下载数据时 我遇到了问题 NSURLSessionConfiguration sessionConfig NSURLSessionConfiguration backgroundSessionConfigur

随机推荐