如何在Windows手机上重新连接接近度

时间:2013-11-15 20:42:49

标签: windows-phone-8 proximity

我有两页...主页和感应网页 首先我从主页转到邻近页面...而且我可以创建与其他手机WP8的连接,

如果我回到主页并再次转到邻近页面,我再也无法连接..

我正在使用这样的代码:

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

        }
    }

我希望有人能帮忙......谢谢

0 个答案:

没有答案