OGeek|极客世界-中国程序员成长平台

标题: ios - iPhone SDK : GameKit and large files + connection lost [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:41
标题: ios - iPhone SDK : GameKit and large files + connection lost

我一直在玩 GameKit,但现在我面临着非常严重的困难。

我将通过蓝牙发送更大的文件 - 1-2MB。我已经准备了一个数据包(每个大约 8kB)。

我的应用程序按照以下方案所述运行:

iPhone - sending header: file divided into 25 parts
iPod - received header: OK I got it waiting for 25 parts
iPhone - sending part #1
iPod - received part #1 send next
iPhone - sending part #2
iPod - received part #2 send next
...
iPhone - sending part #24
iPod - received part #24 send next
iPhone - sending part #25
iPod receiving part #25 processing file

我使用以下方式发送文件部分和消息(确认发送):

[mSession sendData:data toPeers:mPeers withDataMode:GKSendDataReliable error:nil];

并接收数据:

- (void)receiveDataNSData *)data fromPeerNSString *)peer inSession: (GKSession *)session contextvoid *)context

我想知道您如何处理蓝牙传输过程中可能出现的一些问题。浏览文档 GKSessionDelegate 不会给我任何数据是否已交付的信息。

在 90% 的情况下,传输工作正常,但有时它会突然停止并且在不重新连接/重新启动应用程序的情况下无法继续。

如果我在 1 秒内没有得到响应,我试图发明一个简单的解决方案来重新设置数据:

-(void)sendAgain {
    [self sendData:bufor];
}
-(void)sendDataNSData *)data {
    bufor = [data retain];

    timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selectorselector(sendAgain) userInfo:nil repeats:NO];

    [mSession sendData:data toPeers:mPeers withDataMode:GKSendDataReliable error:nil];
}

如果发件人收到文件部分成功传送的确认,timeOutTimer 无效。但事实上,当我实现这个解决方案时,问题就更多了。

桌面上的设备彼此相邻。

您如何处理设备之间“未传递”数据的问题?它只是一个工具,但在开发游戏时它怎么会烦人呢?

顺便说一句,发送简短的聊天消息从来没有造成任何问题,而且我正在使用相同的方法。

事实上,连接很少会丢失,只是数据喜欢在空中丢失。我已经在划分部分,所以数据的大小大约是 8kb,这真的让图像的传输真的很慢。



Best Answer-推荐答案


GameKit 框架在这一点上并不是很可靠,即使对于我正在开发的游戏的简单数据交换也是如此。我不会用它来传输大数据,你只是在问头。

关于ios - iPhone SDK : GameKit and large files + connection lost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1357254/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4