加載聲音時我現在有我的應用程序的設置是這樣的:的Xcode - 蘋果的Mach-O鏈接錯誤,在AppDelegate中
我設置在AppDelegate.h的extern
變量,因爲我讀過他們作爲一個全局變量。還添加了AudioToolbox框架。
AppDelegate.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
extern SystemSoundID tapSoundID;
@end
接下來,我將我的代碼,因爲我要爲應用程序的完成開始儘快加載的聲音加載在AppDelegate中的didFinishLaunching方法的踢踏聲。
AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Load Tap Sound
NSURL *tapSoundPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"tap" ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)tapSoundPath, &tapSoundID);
return YES;
}
@end
確信導入我的標題畫面視圖控制器AppDelegate.h
類。
TitleScreen.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
最後,我使用AudioServicesPlaySystemSound(tapSoundID);
當按鈕被點擊播放聲音。
TitleScreen.m
#import "TitleScreen.h"
@interface TitleScreen()
@end
@implementation TitleScreen
- (IBAction)buttonToGameScreen:(id)sender{
AudioServicesPlaySystemSound(tapSoundID);
}
@end
老實說,我認爲這會工作,和Xcode中沒有表現出任何警告或錯誤,直到我試圖運行應用程序:
構建失敗:蘋果Mach-O Linker錯誤
Undefined symbols for architecture armv7:
"_tapSoundID", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
-[TitleScreen goToGameplay:] in TitleScreen.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我不知道這些錯誤是什麼意思。我是Objective-C/iOS編程的新手,我花了好幾個小時試圖自己弄清楚這一點,但我不能。請幫忙。
你的意思是在'TitleScreen.h'中有'@ interface'嗎? – NobodyNada 2015-02-08 23:52:32