问题描述
根据Apple文档,AudioServices.h应该是AudioToolbox框架的一部分。
According to the apple documentation, AudioServices.h should be part of the AudioToolbox framework.
即使我已经将AudioToolbox框架添加到我的Xcode项目中,当我#import AudioServices我收到错误:找不到AudioServices.h文件。
Even though I have added the AudioToolbox framework to my Xcode project, when I #import AudioServices I get the error: AudioServices.h file not found.
无论我输入
#importAudioServices.h,都会发生这种情况
This happens whether I type #import "AudioServices.h"
或
#importAudioToolbox / AudioServices.h
。
or #import "AudioToolbox/AudioServices.h".
以防万一,我尝试删除然后重新添加AudioToolbox框架,这没有任何效果。 AudioServices文件可能会以某种方式被破坏吗? (如果有,有谁知道我可以在哪里下载另一个副本?)
Just in case, I tried removing and then re-adding the AudioToolbox framework, which had no effect. Could the AudioServices file be corrupted somehow? (If so, does anyone know where I could download another copy?)
我正在使用XCode 4.2,但是当我转换一些旧的开源代码时,项目是设置为XCode 3.2兼容。这可能是问题吗?
I am using XCode 4.2, but as I am converting some old open source code, the project is set to be XCode 3.2-compatible. Could this be the issue?
我确定我错过了一些简单的事情。我对编程很陌生......任何帮助都很感激!
I'm sure I'm missing something simple. I am totally new to programming... any help appreciated!
-----编辑(见下面的评论)-----
-----EDIT (see my comment below)-----
,这两个函数有问题:
extern OSStatus
AudioSessionInitialize( CFRunLoopRef inRunLoop,
CFStringRef inRunLoopMode,
AudioSessionInterruptionListener inInterruptionListener,
void *inClientData)
extern OSStatus
AudioSessionAddPropertyListener( AudioSessionPropertyID inID,
AudioSessionPropertyListener inProc,
void *inClientData)
在SpeakHereController.mm中(来自示例Apple代码) ),我试图转换为ARC以使其合作b etter与我项目中的其他文件:
in SpeakHereController.mm (from sample Apple code), which I am trying to convert to ARC to get it to cooperate better with the other files in my project:
- (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 强制转换为void *。在AudioSessionInitialize函数(和其他)的最后一个参数中使用Self。
The problem is that the system can't cast self to void * automatically when you're using ARC. Self is used in the last parameter of AudioSessionInitialize function (and others).
您需要告诉ARC如何通过手动将其转换为void来控制内存的所有权*使用__bridge。这表示不要更改内存的所有权。
You need to tell ARC how the ownership of the memory is controlled by manually casting it to void * using __bridge. This says 'Don't change ownership of the memory'.
因此,在调用AudioSession函数时,将self更改为(__bridge void *)self。
So change self to (__bridge void *)self in the calls to the AudioSession functions.
例如
OSStatus error = AudioSessionInitialize(NULL, NULL, interruptionListener, (__bridge void*)self);
这篇关于在包含AudioToolbox框架的objective-C iOS项目中找不到AudioServices.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!