我在 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;
}
谁能看到我做错了什么?