问题
I have a sample iPhone application taken from https://github.com/KhaosT/CBPeripheralManager-Demo/tree/master/PeripheralModeTest. I am advertising my peripheral service as follows.
- (void)peripheralManager:(CBPeripheralManager *)peripheral didAddService:(CBService *)service error:(NSError *)error
{
NSLog(@"didAddService start");
NSLog(@"Added");
NSDictionary *advertisingData = @{CBAdvertisementDataLocalNameKey : @"BTService", CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:@"EBA38950-0D9B-4DBA-B0DF-BC7196DD44FC"]]};
[peripheral startAdvertising:advertisingData];
NSLog(@"didAddService end");
}
I have taken windows app code sample from https://code.msdn.microsoft.com/windowsapps/Bluetooth-Generic-5a99ef95. I replaced the Heart rate UUID with the service UUID. But on running it, it is unable to find the service mentioned.
void Scenario1_DeviceEvents::RunButton_Click(Object ^ /* sender */, RoutedEventArgs ^ /* e */)
{
RunButton->IsEnabled = false;
Vector<String^>^ additionalProperties = ref new Vector<String^>;
additionalProperties->Append("System.Devices.ContainerId");
Platform::Guid lol = Platform::Guid::Guid(0xEBA38950, 0x0D9B, 0x4DBA, 0xB0, 0xDF, 0xBC, 0x71, 0x96, 0xDD, 0x44, 0xFC);
create_task(DeviceInformation::FindAllAsync(
GattDeviceService::GetDeviceSelectorFromUuid(lol), additionalProperties))
.then([this](Windows::Devices::Enumeration::DeviceInformationCollection^ devices)
{
this->devices = devices;
if (devices->Size > 0)
{
Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, devices]()
{
DevicesListBox->Items->Clear();
auto serviceNames = ref new Vector<String^>();
for_each(begin(devices), end(devices), [=](DeviceInformation^ device)
{
serviceNames->Append(device->Name);
});
cvs->Source = serviceNames;
DevicesListBox->Visibility = Windows::UI::Xaml::Visibility::Visible;
}));
}
else
{
MainPage::Current->NotifyUser(L"Could not find any Heart Rate devices. Please make sure your " +
"device is paired and powered on!",
NotifyType::StatusMessage);
}
Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]()
{
RunButton->IsEnabled = true;
}));
}).then([](task<void> finalTask)
{
try
{
// Capture any errors and exceptions that occured during device discovery
finalTask.get();
}
catch (COMException^ e)
{
MainPage::Current->NotifyUser("Error: " + e->Message, NotifyType::ErrorMessage);
}
});
}
I tried pairing the device with windows. But still no luck. It has been so frustating, no proper support for discovering devices.
来源:https://stackoverflow.com/questions/27287558/windows-8-0-not-discovering-cbperipheral