Please please could someone explain what is going on in the GKTapper sample code!
Specifically - I call authenticateLocalUser and it works just fine BUT what is callDelegateOnMainThread actually doing and why does it not seem to pass any argument (@selector???) and thus outputs "Missed Method" to the console?
If someone understands this please take a moment to explain it to me!
Code is unchanged from the GKTapper sample from Apple:
Specifically - I call authenticateLocalUser and it works just fine BUT what is callDelegateOnMainThread actually doing and why does it not seem to pass any argument (@selector???) and thus outputs "Missed Method" to the console?
If someone understands this please take a moment to explain it to me!
Code is unchanged from the GKTapper sample from Apple:
Code:
- (void) authenticateLocalUser
{
if([GKLocalPlayer localPlayer].authenticated == NO)
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
{
[self callDelegateOnMainThread: @selector(processGameCenterAuth:) withArg: NULL error: error];
}];
}
}
- (void) callDelegateOnMainThread: (SEL) selector withArg: (id) arg error: (NSError*) err
{
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self callDelegate: selector withArg: arg error: err];
});
}
- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
assert([NSThread isMainThread]);
if([delegate respondsToSelector: selector])
{
if(arg != NULL)
{
[delegate performSelector: selector withObject: arg withObject: err];
NSLog(@"delegate with arg");
}
else
{
[delegate performSelector: selector withObject: err];
NSLog(@"delegate without arg");
}
}
else
{
NSLog(@"delegate Missed Method");
}
}