views:

74

answers:

1

Yesterday, I had programmed a simple Bluetooth network for my iPhone application. This morning, when I tried to continue development, it suddenly wasn't working on my iPod Touch 2G at all. It works just fine on the iPAD however. The problem arises when I try and set the availability of my GKSession object to YES on the iPod, having created a Server session. The console receives the following:

2010-10-05 14:28:55.762 Clusters[67:307] BTM: attaching to BTServer
2010-10-05 14:28:55.786 Clusters[67:307] <<< Session >>> +[GKBluetoothSupport _determineBluetoothStatus]: BT not available - try again later.
2010-10-05 14:28:55.862 Clusters[67:307] BTM: posting notification BluetoothAvailabilityChangedNotification

Now, I know that Bluetooth is turned on, and I know that it's working because I downloaded a free Bluetooth transfer app to test that out. I've reset my iPod, cleaned my targets, poked and prodded at various parts of the code, but I just can't find out why the app can't create a Bluetooth server. It can create a Bluetooth client just fine, since the app can receive data sent by my iPad perfectly well.

Can anyone make any suggestions as to what might be happening here? I'm at my wit's end.

A: 

Right, after working away at this all damn day with a million and one dead ends, I finally discovered the culprit. My 'ping' routine. As I guess most people will know, a network session needs to receive regular data or it will timeout and close itself. To prevent this from happening, I set up a simple routine to send a small packet of data (4 bytes) once every ten seconds to all peers. The problem? Using the [GKSession SendDataToAllPeers: withDataMode: error:] method will cause your server to bugger up right royally if there are no peers connected. For some reason, the vital check to see if anyone was connected at all was omitted. I solved the problem by placing a simple predicate in my ping routine like so:

if ([[network peersWithConnectionState:GKPeerStateConnected] count] > 0) {ping code here}

And once again it's working. I can't for the life of me remember this problem happening before, or why it shouldn't happen on the iPad running on an earlier OS. I can only guess that some later update caused the issue. Anyway, all fixed now, and while my program is far from watertight I can at least now concentrate on getting the rest of it working.

-Ash

Ash