Connecting two devices using GKPeerPickerController
GKPeerPickerController* picker;
picker = [[GKPeerPickerController alloc]init];
picker.delegate = self;
picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby; //Here, I suppose, program should use BlueTooth(but it uses the same network).
[picker show];
But if one device is not connected to the wi-fi, everything works fine.
Why setting connectionTypesMask to GKPeerPickerConnectionTypeNearby uses first of all Internet connection and only then uses Bluetooth connection? How to force use only Bluetooth?The only way I found to do that: turn off airport in MacBook and turn on the BT.
This code for GKPeerPickerController delegate method is from Mark and LaMarche Beginning iOS 5 development:
-(GKSession*)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type
{
GKSession *theSession;
if (type == GKPeerPickerConnectionTypeNearby)
{
theSession = [[GKSession alloc] initWithSessionID:kTicTacToeSessionID displayName:nil sessionMode:GKSessionModePeer];
}
return theSession;
}
It will ensure you only connect BT sessions. In their example project some hidden functionality of the peerPicker makes the device ask you to turn on BlueTooth.
精彩评论