2

iOS デバイスからの着信/発信呼び出しがあるときに、以下のイベントを検出したい:

  1. Bluetooth ヘッドセット デバイスが接続されているかどうか。
  2. オーディオが Bluetooth ヘッドセット デバイスにルーティングされるかどうか。

Bluetoothアクセサリのプログラミングは初めてですが、何か方法はありますか?

4

2 に答える 2

1

以下のように解決しました。

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err;

    // close down our current session...
    [audioSession setActive:NO error:nil];
    AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange,   &AudioSessionManager_audioRouteChangedListener, self);


    void AudioSessionManager_audioRouteChangedListener (void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData)
    {
        NSLog(@"AudioSessionManager_audioRouteChangedListener");
        MyAppDelegate *instance = (MyAppDelegate *)inClientData;
        CFDictionaryRef routeChangeDictionary = inData;


        // extract the route change reason...

        CFNumberRef routeChangeReasonRef = CFDictionaryGetValue (routeChangeDictionary, CFSTR(kAudioSession_AudioRouteChangeKey_Reason));
        SInt32 routeChangeReason = kAudioSessionRouteChangeReason_Unknown;
        if (routeChangeReasonRef)
            CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);

        // extract the old route..

        CFStringRef newRoute;
        if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 5.0)
        {
            newRoute = CFDictionaryGetValue(routeChangeDictionary, @"OutputDeviceDidChange_NewRoute");
        }
        else
        {
            newRoute = CFDictionaryGetValue(routeChangeDictionary, @"OutputDeviceDidChange_NewRoute");
        }


        CFStringRef oldRoute;
        oldRoute = CFDictionaryGetValue(routeChangeDictionary, @"OutputDeviceDidChange_OldRoute");
        NSLog(@"newRouteString:%@ oldRoute:%@",newRoute,oldRoute);

        [instance onAudioRouteChangedWithReason:routeChangeReason newRoute:(NSString *)newRoute oldRoute:(NSString *)oldRoute];
    }
于 2013-01-10T05:44:50.397 に答える
1

以下のコードで、「micConnected」の値をチェックして、ヘッドセットが接続されているかどうかを確認します。

AudioSessionInitialize(NULL, NULL, NULL, NULL);    
UInt32 propertySize, micConnected;
    AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &propertySize, &micConnected);
于 2012-11-28T07:14:22.287 に答える