Windows phone 8 如何在windows phone上重新连接邻近功能
我有两页…主页和近页 首先,我从主页转到proximitypage。。然后我就可以和另一部手机WP8建立连接 如果我回到主页,然后再次转到proximitypage,我将无法再次连接 我使用的代码如下:Windows phone 8 如何在windows phone上重新连接邻近功能,windows-phone-8,proximity,Windows Phone 8,Proximity,我有两页…主页和近页 首先,我从主页转到proximitypage。。然后我就可以和另一部手机WP8建立连接 如果我回到主页,然后再次转到proximitypage,我将无法再次连接 我使用的代码如下: public asyc void proximity() { this._proximitydevice = ProximityDevice.GetDefault(); if (this._proximitydevice == null) {
public asyc void proximity()
{
this._proximitydevice = ProximityDevice.GetDefault();
if (this._proximitydevice == null)
{
MessageBox.Show("Ponsel anda tidak didukung NFC!!!");
return;
}
PeerFinder.TriggeredConnectionStateChanged += PeerFinder_TriggeredConnectionStateChanged;
PeerFinder.Start();
}
我希望有人能帮忙……谢谢
void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
{
if (args.State == TriggeredConnectState.PeerFound)
{
WriteMessageText("Peer found. Keep your devices together until the connection is established.\n");
}
else if (args.State == TriggeredConnectState.Completed)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
PhoneApplicationService.Current.State["RemoteHostName"] = args.Socket.Information.RemoteHostName.RawName;
PhoneApplicationService.Current.State["RemoteServiceName"] = args.Socket.Information.RemoteServiceName;
LaunchGame(args.Socket);
});
}
else if (args.State == TriggeredConnectState.Failed || args.State == TriggeredConnectState.Canceled)
{
MessageBoxResult mb = MessageBox.Show("Tidak dapat terhubung dengan ponsel lain. \nIngin menghubungkan kembali ??", "Incuqu", MessageBoxButton.OKCancel);
if (mb != MessageBoxResult.OK)
{
//e.Cancel = true;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
PlayMultiplayer();
//Application.Current.Terminate();
}
}
}