简单的声音播放按钮iPhone SDK

简单的声音播放按钮iPhone SDK,iphone,sdk,audio,Iphone,Sdk,Audio,我已经试了好几个小时,在点击一个按钮后播放一个简单的声音,但我做不到。在尝试了几个教程之后,我在这个链接中遵循了一个教程: 这是.h文件: #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> @interface soundTestViewController : UIViewController{ } -(IBAction) playSound; @end 但是,生成结果会给出错误: Bui

我已经试了好几个小时,在点击一个按钮后播放一个简单的声音,但我做不到。在尝试了几个教程之后,我在这个链接中遵循了一个教程:

这是.h文件:

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface soundTestViewController : UIViewController{

}
-(IBAction) playSound;

@end
但是,生成结果会给出错误:

Build soundTest of project soundTest with configuration Debug

Ld build/Debug-iphonesimulator/soundTest.app/soundTest normal i386
cd /Users/joegeneric/Documents/soundTest
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -L/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest -filelist /Users/joegeneric/Documents/soundTest/build/soundTest.build/Debug-iphonesimulator/soundTest.build/Objects-normal/i386/soundTest.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework AVFoundation -framework AudioToolbox -o /Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator/soundTest.app/soundTest

ld: warning: in /Users/joegeneric/Documents/soundTest/AVFoundation.framework/AVFoundation, missing required architecture i386 in file
ld: warning: in /Users/joegeneric/Documents/soundTest/AudioToolbox.framework/AudioToolbox, missing required architecture i386 in file
Undefined symbols:
  "_AudioServicesPlaySystemSound", referenced from:
      -[soundTestViewController playSound] in soundTestViewController.o
  "_AudioServicesCreateSystemSoundID", referenced from:
      -[soundTestViewController playSound] in soundTestViewController.o
ld: symbol(s) not found

你能展示一下我做错了什么,或者其他关于在iPhone SDK中进行声音播放的更简单的工作教程吗?

你是否向你的目标添加了AudioToolbox框架, 你的代码中有这个导入吗

#import <AudioToolbox/AudioToolbox.h>
#导入

您是否向目标添加了AudioToolbox框架, 你的代码中有这个导入吗

#import <AudioToolbox/AudioToolbox.h>
#导入

[除了massimobio的正确答案]

您提供的教程链接提到了iOS的Xcode 4,但构建结果中的“setenv MACOSX_DEPLOYMENT_TARGET 10.6”行将您的部署目标指示为Mac

您需要将项目构建体系结构更改为iOS,并检查您的目标是iOS,而不是OSX

例如,要更改构建体系结构,请单击项目并选择构建设置以显示基本SDK

此外,您的iAction缺少发件人。它应该在控制器头文件中声明为

-(IBAction) playSound:(id)sender;
并在controller.m文件中实现为

-(IBAction) playSound:(id)sender {
  // your code here
}
另外,不要忘记使用控制拖动将代码中的IBAction链接到XIB,以创建操作目标对


播放声音的最简单演示是SysSound。如果您在示例代码下搜索Xcode文档或通过Apple Developer网站,则可以使用此示例代码。

[此外还有massimobio的正确答案]

您提供的教程链接提到了iOS的Xcode 4,但构建结果中的“setenv MACOSX_DEPLOYMENT_TARGET 10.6”行将您的部署目标指示为Mac

您需要将项目构建体系结构更改为iOS,并检查您的目标是iOS,而不是OSX

例如,要更改构建体系结构,请单击项目并选择构建设置以显示基本SDK

此外,您的iAction缺少发件人。它应该在控制器头文件中声明为

-(IBAction) playSound:(id)sender;
并在controller.m文件中实现为

-(IBAction) playSound:(id)sender {
  // your code here
}
另外,不要忘记使用控制拖动将代码中的IBAction链接到XIB,以创建操作目标对


播放声音的最简单演示是SysSound。如果您在示例代码下搜索Xcode文档或通过Apple Developer网站,它是可用的。

我想如果您已经发布了代码,它会很容易得到帮助。。!我想如果你已经发布了你的代码,它会很容易帮助。。!我的目标是iOS4.2,如果我删除了“playSound”方法,它运行起来没有任何问题。但是当添加这个方法时,它会产生错误。我已经用更多的细节修改了我的答案。希望这能帮上忙。谢谢,但还是不行,可能我的xcode版本3.2太旧了。我不这么认为。您的AudioToolbox调用都需要iOS 2.0及更高版本,因此应该不会有问题。你有没有像我在上面的回答中所说的那样,通过添加“:(id)sender”来修复你的playSound方法?我有,但没有帮助。本周我的目标是iOS 4.2,如果我删除了“playSound”方法,它运行起来没有任何问题。但是当添加这个方法时,它会产生错误。我已经用更多的细节修改了我的答案。希望这能帮上忙。谢谢,但还是不行,可能我的xcode版本3.2太旧了。我不这么认为。您的AudioToolbox调用都需要iOS 2.0及更高版本,因此应该不会有问题。你有没有像我在上面的回答中所说的那样,通过添加“:(id)sender”来修复你的playSound方法?我有,但没有帮助。这个周末真的让我发疯了