private async void DoConnect_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (DiscoveredServices.Items.Count > 0) { int index = DiscoveredServices.SelectedIndex; if (index >= 0) { DiscoveredDeviceWrapper service = (DiscoveredDeviceWrapper)DiscoveredServices.Items[index]; await service.SetServiceOptionsAsync(PreferGO.IsChecked ?? false, SessionInfo.Text); if (provisioningInfo != null && provisioningInfo.IsGroupFormationNeeded && provisioningInfo.SelectedConfigurationMethod != WiFiDirectServiceConfigurationMethod.Default) { // These are the conditions under which a PIN is required service.ConnectAsync(ConnectPin.Text); } else { // No PIN required service.ConnectAsync(); } } } }
// An application has two ways to connect over Wi-Fi Direct services // 1) First call GetProvisioningInfoAsync to begin connecting, // a) if a PIN is required (group formation is required and selected config method is PinEntry or PinDisplay) then call ConnectAsync with the PIN // b) else if no PIN is required then call ConnectAsync with no PIN // 2) Call ConnectAsync to connect without a PIN and prefer the Wi-Fi Direct Default config method, if possible private async void GetProvisioningInfo_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (DiscoveredServices.Items.Count > 0) { int index = DiscoveredServices.SelectedIndex; if (index >= 0) { DiscoveredDeviceWrapper service = (DiscoveredDeviceWrapper)DiscoveredServices.Items[index]; WiFiDirectServiceConfigurationMethod configMethod = WiFiDirectServiceConfigurationMethod.Default; if (((ComboBoxItem)SelectedConfigMethod.SelectedItem).Content.ToString() == "WFDS Default") { configMethod = WiFiDirectServiceConfigurationMethod.Default; } else if (((ComboBoxItem)SelectedConfigMethod.SelectedItem).Content.ToString() == "PIN Keypad") { configMethod = WiFiDirectServiceConfigurationMethod.PinEntry; } else if (((ComboBoxItem)SelectedConfigMethod.SelectedItem).Content.ToString() == "PIN Display") { configMethod = WiFiDirectServiceConfigurationMethod.PinDisplay; } await service.OpenSessionAsync(); await service.SetServiceOptionsAsync(PreferGO.IsChecked ?? false, SessionInfo.Text); provisioningInfo = await service.GetProvisioningInfoAsync(configMethod); } } }