我该如何计划警报声?

时间:2010-11-06 23:38:15

标签: iphone objective-c

我尝试播放alertSound,但我有4个错误,这是我的功能:

#import "AudioToolbox/AudioServices.h"
+(void)jouerSon:(NSString *)fichierSon:(NSString *) extensionFichier
{

NSString* soundPath = [[NSBundle mainBundle] pathForResource:fichierSon ofType:extensionFichier];
CFURLRef baseURL = (CFURLRef) [NSURL fileURLWithPath:soundPath];
SystemSoundID mysound;

AudioServicesCreateSystemSoundID(baseURL,&mysound);
AudioServicesPropertyID flag = 0;
AudioServicesSetProperty(kAudioServicesPropertyIsUISound,sizeof(SystemSoundID), &mysound, sizeof(AudioServicesPropertyID), &flag);

AudioServicesPlayAlertSound(mysound);

//AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

AudioServicesDisposeSystemSoundID(mysound);
}

这是日志错误:

Ld build/Debug-iphonesimulator/ProjetMission.app/ProjetMission normal i386
cd /Users/sylvainlaroche/iPhone/ProjetMission
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.1.sdk -L/Users/sylvainlaroche/iPhone/ProjetMission/build/Debug-iphonesimulator -F/Users/sylvainlaroche/iPhone/ProjetMission/build/Debug-iphonesimulator -filelist /Users/sylvainlaroche/iPhone/ProjetMission/build/ProjetMission.build/Debug-iphonesimulator/ProjetMission.build/Objects-normal/i386/ProjetMission.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -o /Users/sylvainlaroche/iPhone/ProjetMission/build/Debug-iphonesimulator/ProjetMission.app/ProjetMission

Undefined symbols:
  "_AudioServicesDisposeSystemSoundID", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
  "_AudioServicesPlayAlertSound", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
  "_AudioServicesSetProperty", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
  "_AudioServicesCreateSystemSoundID", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

1 个答案:

答案 0 :(得分:5)

您需要将AudioToolbox框架添加到项目中 仅仅进口是不够的。