0

我是 xcode 的新手,并试图制作一个非常简单的应用程序,用于在单击按钮时播放噪音。我问了一个之前的问题,其中我有一个错误,用户建议我没有正确导入 AVFoundation.framework。我接受了他们的建议并设置了导入语句,但现在出现错误。请在下面查看我的代码:

我的 .h 文件:

#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *sampleText;
@end

我的 .m 文件:

#import "FirstViewController.h"
#import <AVFoundation/AVAudioPlayer.h>
@interface FirstViewController ()
@end

@implementation FirstViewController
@synthesize sampleText = _sampleText;

- (IBAction)beep:(UIButton *)sender {
       NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                   pathForResource:@"button1"
                                                   ofType:@"mp3"]];
        AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
        [click play];
    //[click release];
}

但是,在构建时,我收到一个链接器错误:

Undefined symbols for architecture armv7s:
  "_OBJC_CLASS_$_AVAudioPlayer", referenced from:
      objc-class-ref in FirstViewController.o
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有人可以帮我解决这个问题吗?谢谢!

4

2 回答 2

7

您还必须将 AVFoundation 框架添加到您的项目中。单击左侧源列表顶部的项目,选择您的目标,转到“摘要”窗格,然后单击“链接的框架和库”下的“+”按钮。

于 2013-05-21T22:50:09.297 回答
2

确保你也添加了框架。在左栏中单击您的项目,向下滚动到框架并单击添加。找到您需要的框架。

于 2013-05-21T22:49:09.843 回答