ios - 无法导入 AVFoundation.framework,所以应用无法播放音乐?

标签 ios objective-c xcode avaudioplayer

我是 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)

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

最佳答案

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

关于ios - 无法导入 AVFoundation.framework,所以应用无法播放音乐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16680614/

相关文章:

ios - 维基百科图像未从 UIWebView 中的网络存档加载

ios - TabBar 应用程序中的音乐播放器

android - 如何获取 Android iOS 设备的主电子邮件地址

ios - UISearchBar 范围栏背景图像可设置,但不是它的颜色?

ios - 隐式成员表达式是用 Swift 编写的首选方式吗

iPhone:如何在 MapKit 上的两点之间画线?

objective-c - UIKeyboard-关闭大写锁定键

iphone - dispatch_async 被触发 10 次

iphone - 自定义 UIMenuController

ios - TableView (_ : cellForRowAtIndexPath) is not called and TableView doesn't show any data