如何计划警报声音

如何计划警报声音

我试图播放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

最佳答案

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

关于iphone - 如何计划警报声音?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4115751/

10-09 10:20