0

我有一个来自https://github.com/KhaosT/CBPeripheralManager-Demo/tree/master/PeripheralModeTest的示例 iPhone 应用程序。我正在宣传我的外围服务,如下所示。

- (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");
}

我从https://code.msdn.microsoft.com/windowsapps/Bluetooth-Generic-5a99ef95获取了 Windows 应用程序代码示例。我用服务 UUID 替换了心率 UUID。但是在运行它时,它找不到提到的服务。

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);
        }
    });
}

我尝试将设备与 Windows 配对。但仍然没有运气。太令人沮丧了,对发现设备没有适当的支持。

4

0 回答 0