views:

497

answers:

2
+1  Q: 

NSError question

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 i 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 **. Thank You.

+6  A: 

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

NSError* error=nil;
[session acceptConnectionFromPeer:peerID error:&error];
jdelStrother
That got rid of an error. What should i really put in there though, if i want to construct an error to come up.
Adam Libonatti-Roche
jdelStrother
`-acceptConnectionFromPeer: error:` assigns an autoreleased `NSError` to the pointer. You can check if there was an error with `if (error) { printf("ERROR"); }`
Georg
A: 

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.

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

Niels Castle
You can't return `nil` (or anything, really) from a method of return type `void`.
Quinn Taylor