iphone - 在 iOS Game Kit 中,是接收数据 :fromPeer:inSession:context part of a delegate protocol?

标签 iphone objective-c ios delegates gamekit

通常,Xcode 中的自动完成功能会自动完成该类的方法名称,如果该类位于其他对象的委托(delegate)中,则方法名称如下:

@interface ViewController : UIViewController <UIAlertViewDelegate, 
                                              GKPeerPickerControllerDelegate>

但是对于 Game Kit 的方法,要在 ViewController.m 里面:
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer 
           inSession: (GKSession *)session context:(void *)context {
     // ...
}

它似乎不是任何委托(delegate)方法的一部分,无论是通过 Xcode 的自动完成还是在任何文档中?如果它不是委托(delegate)的一部分,为什么它与所有其他委托(delegate)方法的工作方式不同?

更新:如果我搜索所有头文件:
grep -r receiveData /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

包含该行的唯一文件是:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/GameKit.framework/Headers/GKSession.h:- (void)setDataReceiveHandler:(id)handler withContext:(void *)context; // SEL = -receiveData:fromPeer:inSession:context:



所以它只出现在评论中......

最佳答案

setDataReceiveHandler:withContext: 的文档GKSession 中的方法类 说:

The handler must implement a method with the following signature:

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;


这并不能回答您为什么没有像普通委托(delegate)方法那样实现此方法的问题。我想这个实现提供了更大的灵 active ,因为你可以让一个对象响应GKSession。管理连接的委托(delegate)方法,同时指定一个不同的对象在建立连接后处理传入的数据。
无论如何,希望这能回答这个方法在哪里定义的实际问题,这让我摸不着头脑。

关于iphone - 在 iOS Game Kit 中,是接收数据 :fromPeer:inSession:context part of a delegate protocol?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12334194/

相关文章:

ios - NSLocale 大部分是空的 - 属性在哪里?

ios - 如何在Objective C中通过UIView获取UIAlertController?

iphone - 在类似拨号器的 View 中星号太小

iphone - 帮助调试 iPhone 应用程序 - EXC_BAD_ACCESS

iphone - Array addObject 正在更改所有数组值,而不仅仅是附加

ios - 在打开照片库并选择一张照片以在单击的单元格中设置此照片后,获取我单击的单元格的 IndexPath

ios - UIViewControllers 中带有许多 UITableVIew 的 UIScrollView 消失了 UITableViewCell 的点击

ios - 使用 CCClippingNode 的屏幕截图 - cocos2d-iphone-2.1-beta4

ios - 从 iPhone 中的字符串中获取子字符串

ruby-on-rails - 保护 iOS 应用程序和 Rails 应用程序之间通信的最简单方法是什么?