蓝牙不可用 - 稍后重试

发布于 2024-09-26 03:43:50 字数 730 浏览 3 评论 0原文

昨天,我为我的 iPhone 应用程序编写了一个简单的蓝牙网络。今天早上,当我尝试继续开发时,它突然在我的 iPod Touch 2G 上根本无法运行。不过它在 iPAD 上运行得很好。当我尝试在 iPod 上将 GKSession 对象的可用性设置为“是”并创建服务器会话时,问题就出现了。控制台收到以下信息:

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

现在,我知道蓝牙已打开,并且我知道它正在工作,因为我下载了免费的蓝牙传输应用程序来测试它。我重置了我的 iPod,清理了我的目标,反复检查了代码的各个部分,但我就是不明白为什么该应用程序无法创建蓝牙服务器。它可以很好地创建蓝牙客户端,因为该应用程序可以很好地接收我的 iPad 发送的数据。

任何人都可以对这里可能发生的事情提出任何建议吗?我已经无计可施了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小红帽 2024-10-03 03:43:50

是的,在这该死的一百万零一个死胡同里工作了一整天后,我终于找到了罪魁祸首。我的“ping”例程。我想大多数人都知道,网络会话需要定期接收数据,否则会超时并自行关闭。为了防止这种情况发生,我设置了一个简单的例程,每十秒向所有对等点发送一个小数据包(4 字节)。问题?如果没有对等点连接,使用 [GKSession SendDataToAllPeers: withDataMode: error:] 方法将导致您的服务器完全崩溃。由于某种原因,省略了检查是否有人连接的重要检查。我通过在 ping 例程中放置一个简单的谓词解决了这个问题,如下所示:

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

然后它再次起作用了。我一辈子都不记得这个问题以前发生过,也不记得为什么它不应该发生在运行早期操作系统的 iPad 上。我只能猜测是后来的一些更新导致了这个问题。无论如何,现在一切都已修复,虽然我的程序远非无懈可击,但我至少现在可以集中精力让其余部分正常工作。

-灰

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

坐在坟头思考人生 2024-10-03 03:43:50

您还应该做另一件事:在应用程序终止之前关闭 GKSession。您的代码可能是这样的:

// 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;
}

根据我的经验,这足以解决这个问题。

There's another thing you should do: to shutdown your GKSession before your application terminate. Your code could 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, that was enough to fix this issue.

孤单情人 2024-10-03 03:43:50

我也遇到了同样的问题。

前两行表示蓝牙不可用,但第三行表示可用性发生变化。虽然没有记录,但这实际上是说蓝牙正在更改为可用。

所以基本上这个日志消息是一个巨大的干扰,应该被忽略。

I was having the same problem.

The first two lines say Bluetooth is not available, but the third line indicates an availability change. Though it's not logged, this is actually saying that Bluetooth is being changed to available.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文