我在Windows Phone 8中有一个项目,通过蓝牙连接两台设备。当我尝试连接手机和其他设备时,我的手机正在侦听/等待来自其他设备的连接。但是当我的设备发送连接请求时,PeerFinder_ConnectionRequested
事件不会触发。我的代码:
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
PeerFinder.ConnectionRequested += PeerFinder_ConnectionRequested;
}
void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
{
if (ShouldConnect())
{
// Go ahead and connect
ConnectToPeer(args.PeerInformation);
}
}
async void ConnectToPeer(PeerInformation peer)
{
StreamSocket socket = await PeerFinder.ConnectAsync(peer);
MessageBox.Show ("Completed");
}
private bool ShouldConnect()
{
// Determine whether to accept this connection request and return
return true;
}
谁能看到我做错了什么?
答案 0 :(得分:1)
PeerFinder.Start()