这是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>'

我觉得自己犯了一个容易解决的错误,但我不知道这是什么,你们中的任何人都可以帮助我吗?

额外信息
  • 我正在spritekit中执行此操作
  • 最佳答案

    [blockLocalPlayer registerListener:self];
    

    此方法接受符合协议GKLocalPlayerListener的对象。如您在界面中所见,GameKitHelper并未声明它符合GKLocalPlayerListener协议。

    您应该通过以下更改将符合性声明添加到GKLocalPlayerListener中:

    @interface GameKitHelper : NSObject <GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedEventListener>
    

    对此:

    @interface GameKitHelper : NSObject <GKLocalPlayerListener, GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedEventListener>
    

    关于ios - 向基于回合的ios游戏添加事件监听器时发出警告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31971430/

    10-09 01:27