I use PairAsync method to pair another WIFIDirect device by C++, but I can not get "PairingRequested" callback after I push OK button on another device's screen.

LI LIU 31 Reputation points
2022-04-27T00:56:57.32+00:00
      WiFiDirectConnectionParameters connctionParameter = WiFiDirectConnectionParameters();
      connctionParameter.GroupOwnerIntent(0);
      DevicePairingKinds devicePairingKinds = DevicePairingKinds::None;
      connctionParameter.PreferenceOrderedConfigurationMethods().Append(WiFiDirectConfigurationMethod::PushButton);
      devicePairingKinds |= WiFiDirectConnectionParameters::GetDevicePairingKinds(WiFiDirectConfigurationMethod::PushButton);
      connctionParameter.PreferredPairingProcedure(WiFiDirectPairingProcedure::Invitation);
      DeviceInformationCustomPairing customPairing = pairing.Custom();
      event_token token = customPairing.PairingRequested({ this, &WifiDirectClient::PairingRequestedHandler });
      IAsyncOperation<DevicePairingResult> pairingOperation = customPairing.PairAsync(devicePairingKinds, DevicePairingProtectionLevel::None, connctionParameter);
      AsyncStatus pairStatus = pairingOperation.wait_for(TimeSpan(PAIR_TIMEOUT));
      if (pairStatus != AsyncStatus::Completed) {
          if (pairStatus == AsyncStatus::Started) {
              pairingOperation.Cancel();
          }
          return false;
      }
      DevicePairingResult result = pairingOperation.GetResults();
      if (result == nullptr) {
          qDebug() << "result is null";
          return false;
      }
      if (result.Status() != DevicePairingResultStatus::Paired && result.Status() != DevicePairingResultStatus::AlreadyPaired) {
          return false;
      }
      return true;




  void PairingRequestedHandler(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
  {
      DevicePairingKinds kind = args.PairingKind();
      qDebug() << "PairingRequestedHandler : ";
      if (kind == DevicePairingKinds::ConfirmOnly) {
          args.Accept();
      }else {
          qDebug() << "not support pairing kind";
      }
  }

I use PairAsync method to pair another WIFIDirect device by C++, but I can not get "PairingRequested" callback after I push OK button on another device's screen.
wait_for() operation timeout, the errorcode is 0, status is 0.
I can see the confirm dialog pop out on another device screen. And then I push the OK button. But pairasync operation timeout, the errorcode is 0, status is 0.
I also used get() method instead of wait_for(), but pairasync will not return.

Universal Windows Platform (UWP)
{count} vote