bluetooth - GameKit in iPhone SDK 3.0 -


Do I need to use to search for partners in the new iPhone SDK 3.0 < / P>

I really do not want to use it, but I want to use a peer-to-peer Bluetooth connection. Is there a sample code that shows the Bluetooth connection without using a peer picker? The game provided by Apple uses a peer picker, so I can not use it.

Two ways to do this

The first method uses the GameKit API Begin with two separate sections, which implement the G2CessionDelegate protocol and serve as a gamekit / Bluetooth "handler" and the second presentation acts as a UI ( Most likely any kind of visual controller with a table view). The way in which you will wire it, manages the handler gamekit notifications, etc. and then attempts to implement methods on the UI to update the table view after connecting with a colleague. In this way, to arrive and go to devices, your picker list

  - (BOOL) startPeer {BOOL result = no;  

If (! _session) {_session = [[GKSession alloc] initWithSessionID: BLUETOOTHSESSION displayName: zero session mode: GKSessionModePeer]; _session.delegate = self; [_session setDataReceiveHandler: Tag with self: zero]; _session.available = yes; Result = Yes; } Return results; } - (zero) Stoppier {// Set session for next connection // [_session disconnectFromAllPeers]; _session.available = yes; [Self cleaning powered wall]; } - (zero) LoadPeelist {self .Purlist = [[NSMUTABARRRROL] DirectWare: [_ Connection with session partners: GKPeerState available]]; } - (zero) session: (GJSation *) Peer of session: (NSSTING *) PIRID had changed: (GKPER ConnectionState) State {BOOL Peer changed = No; Switch (state) {// When a peer list changes, we adjust the available list // GKPeerState available: if (_peerList) {[_peerList addObject: peerID]; Colleague = yes; } break; // When the peer list changes, we adjust the available list // Case GKPER is unavailable: if (_perlist) {[delete _peerList object: peer ID]; Colleague = yes; } break; // When a colleague has contacted us // Case GKPerState connected: // Reading and starting to read the break; Case GKPeerStateDisconnected: {if (_isWriter) {_isconnected = NO; _deviceToSend = Zero; [Self cleaning powered wall]; } Else {// dropped another party, clear local data and reset for next connection self.dataRead = zero; } } break; } // Notify Pir List Representative that the list has changed so that they can update UI // if (peer-changed) call delegate (_Pierlist DeAgelet, Peerlist Chengal); }

Another way to do this is to use the standard Benzoor Service Selection Mechanism, GameKit is implemented on the top of Bonjour (but instead of WiFi on Bluetooth), so once the two sides They have gone through network access with each other and connected, they are registered under Benzoor and work like any attractive service. GameKit's way is probably a bit easier, but if you already have a code for WiFi, then it can be reused for Bluetooth.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -