-1
我用这个代码来检查,如果事情或缩小在我的iPhone错误同时呼吁audioRouteChangeListenerCallback方法内部目标C法
void audioRouteChangeListenerCallback (void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue) {
// ensure that this callback was invoked for a route change
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
{
// Determines the reason for the route change, to ensure that it is not
// because of a category change.
CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;
CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
SInt32 routeChangeReason;
CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
//Handle Headset Unplugged
NSLog(@"PluggedOut");
}
else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable)
{
//Handle Headset plugged in
NSLog(@"Something Plugged In");
}
}
的audiojack堵塞,但是当我加入我的目标C法(这在所有运行完美其他代码),以确定是否插入设备与EXC_BAD_ACCESS错误我的读卡器它endup我试过低于
else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable)
{
//Handle Headset plugged in
NSLog(@"Something Plugged In");
audiotest *test;
if([test Checkheadphonestatus] == 1)
{
NSLog(@"Your iPosReader Connected");
}
else if([test Checkheadphonestatus] == 0)
{
NSLog(@"Connected device was not iPos Reader");
}
}
}
代码的任何建议,将不胜感激。
是的错误是因为我没有初始化,但现在[测试checkHeadphoneStatus]总是返回0!笏可能是问题? – Dolo 2013-05-01 08:52:30
你可能在'checkHeadphoneStatus'中有一个错误,或者''test'被设置为'nil',它与c/C++中的NULL/nullptr类似,只不过它在你调用的任何方法上总是返回0。检查以确保你的'init'方法工作正常。如果它是你自己的'checkHeadphoneStatus'中的一个错误。 – 2013-05-01 09:34:09