-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