在包含AudioToolbox框架的Objective-C iOS项目中找不到AudioServices.h

根据苹果文档,AudioServices.h应该是AudioToolbox框架的一部分。

即使我已经将AudioToolbox框架添加到我的Xcode项目,当我#import AudioServices我得到错误:AudioServices.h文件未find。

无论我input#import“AudioServices.h”

或#import“AudioToolbox / AudioServices.h”。

以防万一,我试图删除,然后重新添加AudioToolbox框架,没有任何效果。 AudioServices文件可能会损坏吗? (如果是这样,有谁知道我可以下载另一个副本?)

我正在使用XCode 4.2,但是由于我正在转换一些旧的开源代码,因此项目被设置为兼容XCode 3.2。 这可能是问题吗?

我确定我错过了一些简单的事情。 我对编程完全陌生…任何帮助表示赞赏!

—–编辑(看我下面的评论)—–

在AudioServices.h中,有两个问题:

extern OSStatus AudioSessionInitialize( CFRunLoopRef inRunLoop, CFStringRef inRunLoopMode, AudioSessionInterruptionListener inInterruptionListener, void *inClientData) extern OSStatus AudioSessionAddPropertyListener( AudioSessionPropertyID inID, AudioSessionPropertyListener inProc, void *inClientData) 

在SpeakHereController.mm(来自示例苹果代码),我想转换为ARC,以使其与我的项目中的其他文件更好地合作:

 - (void)awakeFromNib { // Allocate our singleton instance for the recorder & player object recorder = new AQRecorder(); player = new AQPlayer(); OSStatus error = AudioSessionInitialize(NULL, NULL, interruptionListener, self); if (error) printf("ERROR INITIALIZING AUDIO SESSION! %ld\n", error); else { UInt32 category = kAudioSessionCategory_PlayAndRecord; error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category); if (error) printf("couldn't set audio category!"); error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, propListener, self); if (error) printf("ERROR ADDING AUDIO SESSION PROP LISTENER! %ld\n", error); UInt32 inputAvailable = 0; UInt32 size = sizeof(inputAvailable); // we do not want to allow recording if input is not available error = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &size, &inputAvailable); if (error) printf("ERROR GETTING INPUT AVAILABILITY! %ld\n", error); btn_record.enabled = (inputAvailable) ? YES : NO; // we also need to listen to see if input availability changes error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioInputAvailable, propListener, self); if (error) printf("ERROR ADDING AUDIO SESSION PROP LISTENER! %ld\n", error); error = AudioSessionSetActive(true); if (error) printf("AudioSessionSetActive (true) failed"); } 

问题在于,当你使用ARC时,系统不能自动抛弃*。 Self用于AudioSessionInitialize函数(及其他)的最后一个参数。

你需要告诉ARC如何通过使用__bridge手动将其转换为void来控制内存的所有权。 这说'不要改变内存的所有权'。

所以把自己改成(__bridge void *)self在对AudioSession函数的调用中。

例如

 OSStatus error = AudioSessionInitialize(NULL, NULL, interruptionListener, (__bridge void*)self); 

尝试“ #import <AudioToolbox/AudioServices.h> ”,看看你的问题是否消失。

<和>字符有所不同。 在“ #import ”中使用双引号意味着您希望编译器search“用户标题”,其中尖括号意味着您希望编译器在系统框架中进行search。