xcode 调用 AudioServicesPlaySystemSound 时出现 2 个错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11919923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:12:50  来源:igfitidea点击:

2 errors when calling AudioServicesPlaySystemSound?

iphonexcodeios5audiotoolboxvibration

提问by n30ncitylights

I'm making an app which vibrates once a timer reaches a certain limit.

我正在制作一个应用程序,一旦计时器达到某个限制就会振动。

However, when calling

但是,当调用

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Xcode comes up with two errors:

Xcode 出现两个错误:

Undefined symbols for architecture i386:
  "_AudioServicesPlaySystemSound", referenced from:
      -[drawGraph drawRect:] in drawGraph.o
ld: symbol(s) not found for architecture i386

and

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas on what is causing these errors?

关于导致这些错误的原因的任何想法?

回答by bitmapdata.com

enter image description here

在此处输入图片说明

If you simply must not add the header files only, as shown above, a framework must be added to your project. and you should a following header. #import <AudioToolbox/AudioToolbox.h>

如果您不能只添加头文件,如上所示,则必须将框架添加到您的项目中。你应该有一个下面的标题。#import <AudioToolbox/AudioToolbox.h>

  1. In Xcode, click your project file at the top of the Project Navigator.

  2. Click 'YourProjectName' under "Targets"

  3. Click the "Build Phases" tab.

  4. Click the plus in the "Link Binary With Libraries" window.

  5. Add the AudioToolbox.Framework library

  6. Add #import <AudioToolbox/AudioToolbox.h>

  1. 在 Xcode 中,单击项目导航器顶部的项目文件。

  2. 单击“目标”下的“您的项目名称”

  3. 单击“构建阶段”选项卡。

  4. 单击“Link Binary With Libraries”窗口中的加号。

  5. 添加 AudioToolbox.Framework 库

  6. 添加 #import <AudioToolbox/AudioToolbox.h>

enter image description here

在此处输入图片说明