iOS 网络编程:在线对战与网络数据获取全解析
在线对战实现
在开发支持在线对战的应用时,若要实现网络对战功能,无论是局域网还是互联网,基本思路有相似之处。
在处理网络会话时,需要考虑到可能出现的错误情况,例如写入错误和连接断开。以下是相关代码示例:
- (void)onlineSession:(OnlineSession *)session
encounteredWriteError:(NSError *)error {
[self showErrorAlertWithTitle:NSLocalizedString(@"Error Writing",
@"Error Writing") message:NSLocalizedString(@"Could not send packet",
@"Could not send packet")];
self.onlineSession = nil;
}
- (void)onlineSessionDisconnected:(OnlineSession *)session {
[self showErrorAlertWithTitle:NSLocalizedString(@"Peer Disconnected",
@"Peer Disconnected") message:NSLocalizedString(
@"Your opponent disconnected or otherwise could not be reached.",
超级会员免费看
订阅专栏 解锁全文
90

被折叠的 条评论
为什么被折叠?



