C 函数中无法识别 Objective C 对象
我正在为 kAudioSessionProperty_AudioRouteChange 添加音频会话属性侦听器,并且在回调中我想调用 UIImagePickerController 的 takePicture 函数。问题是我无法在回调中访问我的选择器。
我正在 viewDidLoad 中初始化我的选择器。我尝试将选择器声明为私有和公共对象,并使用 picker 或 self.picker 进行访问,但它总是给出“使用未声明的标识符”错误。我使用此代码添加侦听器:
AudioSessionInitialize(nil, nil, nil, nil);
AudioSessionSetActive(true);
AudioSessionAddPropertyListener(
kAudioSessionProperty_AudioRouteChange,
applicationAudioRouteDidChange,
self);
这是我的回调:
void applicationVolumeDidChange(void *inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize, const void *inData)
{
NSLog(@"Volume changed");
//[picker takePicture]; Error
}
我还声明了一个 NSArray 以查看这是否仅是 UIImagePickerController 的问题,但该数组也给出了相同的错误。
I am adding an Audio session property listener for kAudioSessionProperty_AudioRouteChange and in the callback I want to call the takePicture function of UIImagePickerController. The problem is that I cannot access my picker in the callback.
I am initializing my picker in viewDidLoad. I have tried declaring the picker as both a private and public object and accessing with picker or self.picker but it always gives the "Use of undeclared identifier" error. I use this code to add the listener:
AudioSessionInitialize(nil, nil, nil, nil);
AudioSessionSetActive(true);
AudioSessionAddPropertyListener(
kAudioSessionProperty_AudioRouteChange,
applicationAudioRouteDidChange,
self);
This is my callback:
void applicationVolumeDidChange(void *inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize, const void *inData)
{
NSLog(@"Volume changed");
//[picker takePicture]; Error
}
I also declared an NSArray to see if this was the problem with UIImagePickerController only but the array also gives the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AudioSessionAddPropertyListener() 的最后一个参数就在那里,因此您可以将您喜欢的任何内容传递到回调中。
您正在传递 self,因此在回调中,
void *inClientData
参数是指向 self 对象的指针。如果 self 是 UIImagePickerController 的实例,
The last parameter of
AudioSessionAddPropertyListener()
is there so you can pass whatever you like into the callback.You are passing self so within the callback the
void *inClientData
parameter is a pointer to whichever object self is.If self was an instance of UIImagePickerController then,
您的回调必须是 C 函数,而不是 Objective-C 方法。这些不兼容。请参阅此链接。
Your callbacks must be C functions, not Objective-C methods. These are not compatible. See this link.