Bluetooth not available - try again later

Yesterday, I programmed a simple Bluetooth network for my iPhone application. This morning, when I tried to continue development, it suddenly did not work on my iPod Touch 2G. However, it works great on iPAD. The problem occurs when I try to make my GKSession object accessible to YES on iPod by creating 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 works because I downloaded the free Bluetooth transfer app to check it out. I reset my iPod, cleared my goals, poked and pushed to various parts of the code, but I just can’t understand why the application cannot create a Bluetooth server. It can create a Bluetooth client just fine, as the application can receive data sent by my iPad perfectly.

Can anyone make any suggestions as to what might be happening here? I am at my end.

+4
source share
3 answers

Well, after practicing that damn whole day with a million and one dead end, I finally discovered the culprit. My ping procedure. As I think, most people will find out that the network session should receive regular data or it will time out and close. To prevent this from happening, I set up a simple procedure for sending a small data packet (4 bytes) every 10 seconds to all peers. Problem? Using the [GKSession SendDataToAllPeers: withDataMode: error:] method will cause your server to be fixed correctly if there are no peers connected. For some reason, a vital check to make sure that someone was connected at all was omitted. I solved the problem by setting a simple predicate in my ping procedure like this:

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

And again it works. I can’t let my life remember that this problem occurs earlier, or why this should not happen on an iPad running on an earlier OS. I can only guess that some late update caused this problem. In any case, everything is fixed now, and while my program is far from waterproof, I can at least now concentrate on making everything else work.

-Ash

+3
source

Another thing you have to do: close your GKSession before your application exits. Your code might be something like this:

 // YourAppDelegate.m - (void)applicationWillTerminate:(UIApplication *)application { [[Business sharedInstance] shutdownBluetooth]; } // Business.m // considering that you have a GKSession instance on 'session' variable - (void)shutdownBluetooth { [self.session disconnectFromAllPeers]; self.session.available = NO; [self.session setDataReceiveHandler:nil withContext:nil]; self.session.delegate = nil; self.session = nil; } 

In my experience, this was enough to fix this problem.

+1
source

I had the same problem.

The first two lines say that Bluetooth is not available, but the third line indicates a change in availability. Although not registered, it actually means that Bluetooth is becoming available.

So basically this journal message is a huge distraction and should just be ignored.

0
source

All Articles