这是gamekithelper.m中的代码
- (void)authenticateLocalPlayer
{
//1
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
//add a weak local player
__weak GKLocalPlayer *blockLocalPlayer = localPlayer;
if (localPlayer.isAuthenticated) {
[[NSNotificationCenter defaultCenter] postNotificationName:LocalPlayerIsAuthenticated object:nil];
return;
}
//2
localPlayer.authenticateHandler =
^(UIViewController *viewController, NSError *error) {
//3
[self setLastError:error];
if(viewController != nil) {
//4
[self setAuthenticationViewController:viewController];
*******problem code************
// add event handler
[blockLocalPlayer registerListener:self];
} else if([GKLocalPlayer localPlayer].isAuthenticated) {
//5
_enableGameCenter = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:LocalPlayerIsAuthenticated object:nil];
*******problem code************
// add event handler
[blockLocalPlayer registerListener:self];
} else {
//6
_enableGameCenter = NO;
}
};
}
这是gamekithelper.h中的@interface
@interface GameKitHelper : NSObject <GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedEventListener>
这是警告
Sending 'GameKitHelper *const __strong' to parameter of incompatible type 'id<GKLocalPlayerListener>'
我觉得我犯了一个容易修复的错误,但我无法弄清楚它是什么,你们中的任何人都可以帮助我吗?
额外信息
答案 0 :(得分:3)
[blockLocalPlayer registerListener:self];
此方法接受符合协议GKLocalPlayerListener
的对象。正如您在界面中看到的那样,GameKitHelper
并未声明它符合GKLocalPlayerListener
协议。
您应该通过更改此项来添加GKLocalPlayerListener
的一致性声明:
@interface GameKitHelper : NSObject <GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedEventListener>
到此:
@interface GameKitHelper : NSObject <GKLocalPlayerListener, GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedEventListener>