warning when adding event listener to turn based ios game

时光毁灭记忆、已成空白 提交于 2019-12-10 19:07:29

问题


here is the code in 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;
         }
     };

}

here is the @interface in gamekithelper.h

@interface GameKitHelper : NSObject <GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedEventListener>

here is the warning

Sending 'GameKitHelper *const __strong' to parameter of incompatible type 'id<GKLocalPlayerListener>'

I feel like I am making an easily fixable mistake but I can't figure out what it is, can any of you help me out?

Extra info

  • I am doing this in spritekit

回答1:


[blockLocalPlayer registerListener:self];

This method accepts an object that conforms to the protocol GKLocalPlayerListener. As you can see in your interface, GameKitHelper does not state that it conforms to the GKLocalPlayerListener protocol.

You should add the declaration of conformance to GKLocalPlayerListener by changing this:

@interface GameKitHelper : NSObject <GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedEventListener>

to this:

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


来源:https://stackoverflow.com/questions/31971430/warning-when-adding-event-listener-to-turn-based-ios-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!