我应该将什么作为参数传递给期望NSError **的方法?

时间:2020-12-01 00:18:39

I have been creating a peer to peer connection for a new game, that does not use the peer picker. I am however dumbstruck as what to put in here:

我一直在为新游戏创建一个对等连接,不使用对等选择器。然而,我对这里的内容感到愚蠢:

- (void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSString *)peerID {
    NSLog(@"I GOTS A CONNECTION REQUEST");
    if(connected == YES) {
        //deny all requests
    }
    else if(connected == NO) {
        [session acceptConnectionFromPeer:peerID error:???];
    }
}

What should I put where the question marks are? The documentation says NSError **.

我应该把问号放在哪里?文档说NSError **。

2 个解决方案

#1


7  

It's a pointer to an NSError*, so :

它是指向NSError *的指针,因此:

NSError* error=nil;
[session acceptConnectionFromPeer:peerID error:&error];

#2


0  

If there is no error set error to nil.

如果没有错误设置错误为零。

error is a means of conveying to the rest of your application why the connection is not beeing established.

错误是一种向您的应用程序的其余部分传达为什么没有建立连接的方法。

In you example roll your own NSError stating that your application is not accepting connections because it is already connected to a client.

在您的示例中,滚动您自己的NSError,指出您的应用程序不接受连接,因为它已连接到客户端。

See the iPhone Dev Center documentation for NSError to see how to populate it.

有关NSError的信息,请参阅iPhone Dev Center文档,了解如何填充它。

#1


7  

It's a pointer to an NSError*, so :

它是指向NSError *的指针,因此:

NSError* error=nil;
[session acceptConnectionFromPeer:peerID error:&error];

#2


0  

If there is no error set error to nil.

如果没有错误设置错误为零。

error is a means of conveying to the rest of your application why the connection is not beeing established.

错误是一种向您的应用程序的其余部分传达为什么没有建立连接的方法。

In you example roll your own NSError stating that your application is not accepting connections because it is already connected to a client.

在您的示例中,滚动您自己的NSError,指出您的应用程序不接受连接,因为它已连接到客户端。

See the iPhone Dev Center documentation for NSError to see how to populate it.

有关NSError的信息,请参阅iPhone Dev Center文档,了解如何填充它。