开发者

Connecting two devices using GKPeerPickerController

I have three devices(mac, ipod, iphone) all of them are connected to the wi-fi. When I am testing application, that connects two devices, both ask to switch on the bluetooth, but anyway, they want to use wi-fi. how to force them to use bluetoot开发者_StackOverflow中文版h instead of wi-fi.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜