سؤال

باستخدام iPhone SDK 3.1.2.

هل هناك على أي حال معرفة ما إذا كانت سماعات رأس Bluetooth متصلة بالجهاز؟ لا تحتاج إلى أي معلومات إلا إذا كانت متصلة أم لا. هذا يختلف عن معرفة ما إذا كان أحد تم توصيله أم لا يمكن للمرء القيام به عبر مستمع خاص للجلسة الصوتية.

شكرا

لا يوجد حل صحيح

نصائح أخرى

استدعاء هذه الطريقة لمعرفة سماعة Bluetooth متصلة أم لا.

أولا استيراد هذا الإطار #import <AVFoundation/AVFoundation.h>

- (BOOL) isBluetoothHeadsetConnected
    {
        AVAudioSession *session = [AVAudioSession sharedInstance];
        AVAudioSessionRouteDescription *routeDescription = [session currentRoute];

        NSLog(@"Current Routes : %@", routeDescription);

        if (routeDescription)
        {
            NSArray *outputs = [routeDescription outputs];

            if (outputs && [outputs count] > 0)
            {
                AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0];
                NSString *portType = [portDescription portType];

                NSLog(@"dataSourceName : %@", portType);

                if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"])
                {
                    return YES;
                }
            }
        }

        return NO;
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top