簡體   English   中英

獲取經典的藍牙連接設備列表(無BLE)[EAAccessoryManager]

[英]Get the list of classic bluetooth connected devices (no BLE) [EAAccessoryManager]

我需要做一個應用程序,該應用程序可以判斷我當前是否已連接經典的藍牙設備(實際上,它將是藍牙車載設備)。

我的第一步是告訴當前連接的經典藍牙設備是什么。 我不能使用CoreBluetooth,因為它僅用於LE。 我嘗試使用外部附件框架。

這是代碼(一個按鈕啟動方法):

- (IBAction)startMethodGetConnected:(id)sender {
     NSLog(@"button taped");
     // Get the number of accessories connected
     NSUInteger NumberOfAccessoriesConnected = [[EAAccessoryManager sharedAccessoryManager].connectedAccessories count];
     //Display the number 
     NSLog(@"number of accessories connected : %d", NumberOfAccessoriesConnected);
 }

我已嘗試將iPhone連接到藍牙鍵盤和藍牙耳機。 在這兩種情況下,控制台都會顯示數字為0。

如何顯示正確的號碼?

從蘋果文檔:

“支持外部附件的應用程序必須確保正確配置其Info.plist文件。特別是, 您必須包括 UISupportedExternalAccessoryProtocols鍵,以聲明應用程序支持的特定硬件協議。有關此框架的更多信息,請參見外部附件編程主題。” 這里

您需要使用MFi設備的協議將此密鑰添加到Info.plist文件中。

<key>UISupportedExternalAccessoryProtocols</key>
<array>
    <string>your_protocol_name</string>
</array>

問候

你不能。 您可以做的是檢查播放路徑。 問題在於您的汽車免提將是HeadsetBT。 這是我在應用程序中使用的代碼。

// create and set up the audio session
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setDelegate:self];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive: YES error: nil];

// set up for bluetooth microphone input
UInt32 allowBluetoothInput = 1;
OSStatus stat = AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                                         sizeof (allowBluetoothInput),
                                         &allowBluetoothInput
                                         );
NSLog(@"status = %x", stat);    // problem if this is not zero

// check the audio route
UInt32 size = sizeof(CFStringRef);
CFStringRef route;
OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route);
NSLog(@"route = %@", route);
// if bluetooth headset connected, should be "HeadsetBT"
// if not connected, will be "ReceiverAndMicrophone"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM