gpt4 book ai didi

ios - 哪个类用于实现 GKLocalPlayerListener 协议(protocol)

转载 作者:行者123 更新时间:2023-12-01 17:54:51 26 4
gpt4 key购买 nike

我正在尝试在我的代码中实现 GKChallengeListener,并且我使用了来自苹果的 GameCenterManager 类。玩家身份验证良好,排行榜和挑战也是如此。But i want to notify my application when the remote player completed the challenge. for this i have used GKChallengeListener protocols. but they are not calling up when i am sending or receiving the challenges引用自。但我不明白哪个类(class)会将委托(delegate)人称为自我
https://developer.apple.com/library/ios/documentation/GameKit/Reference/GKEventListener_Ref/Reference/Reference.html#//apple_ref/occ/intf/GKChallengeListener

在 ViewController.h

@interface ViewController : UIViewController <UIActionSheetDelegate, GameCenterManagerDelegate,GKGameCenterControllerDelegate,GKChallengeListener> {
GameCenterManager *gameCenterManager;
NSInteger currentScore;
NSString* currentLeaderBoard;
IBOutlet UILabel *currentScoreLabel;
}
@property (nonatomic, retain) GameCenterManager *gameCenterManager;
@property (nonatomic, assign) NSInteger currentScore;
@property (nonatomic, retain) NSString* currentLeaderBoard;
@property (nonatomic, retain) UILabel *currentScoreLabel;
- (IBAction) showLeaderboard;
- (IBAction) increaseScore;

@结尾

在 ViewController.m 中
@implementation ViewController

@synthesize gameCenterManager;
@synthesize currentScore;
@synthesize currentLeaderBoard;
@synthesize currentScoreLabel;

- (void)viewDidLoad
{
[super viewDidLoad];
self.currentLeaderBoard = kLeaderboardID;
self.currentScore = 0;
if ([GameCenterManager isGameCenterAvailable]) {
self.gameCenterManager = [[GameCenterManager alloc] init];
[self.gameCenterManager setDelegate:self];
[self.gameCenterManager authenticateLocalUser];
} else {
// The current device does not support Game Center.
}
}

-(void)player:(GKPlayer *)player issuedChallengeWasCompleted:(GKChallenge *)challenge byFriend:(GKPlayer *)friendPlayer{
NSLog(@"issued challenge was completed by friend");

}
-(void)player:(GKPlayer *)player didCompleteChallenge:(GKChallenge *)challenge issuedByFriend:(GKPlayer *)friendPlayer{
NSLog(@"player did complete challenge");
}
-(void)player:(GKPlayer *)player didReceiveChallenge:(GKChallenge *)challenge{
NSLog(@"player did recieve challenge");
}
-(void)player:(GKPlayer *)player wantsToPlayChallenge:(GKChallenge *)challenge{
NSLog(@"player wants to play challenge ");
}

最佳答案

这在 iOS 7.0 中已被弃用,但您仍然可以使用它作为替代方法

- (void)viewDidLoad
{
[super viewDidLoad];
self.currentLeaderBoard = kLeaderboardID;
self.currentScore = 0;
if ([GameCenterManager isGameCenterAvailable]) {

self.gameCenterManager = [[GameCenterManager alloc] init];
[self.gameCenterManager setDelegate:self];
[self.gameCenterManager authenticateLocalUser];
} else {
// The current device does not support Game Center.
}
GKChallengeEventHandler
*gk
=[GKChallengeEventHandler challengeEventHandler].delegate=self;
}

- (void)localPlayerDidCompleteChallenge:(GKChallenge *)challenge
{
NSLog(@"localPlayerDidCompleteChallenge");
}
- (void)localPlayerDidReceiveChallenge:(GKChallenge *)challenge
{
NSLog(@"localPlayerDidReceiveChallenge");
}
- (void)localPlayerDidSelectChallenge:(GKChallenge *)challenge{
NSLog(@"localPlayerDidSelectChallenge");
}
- (void)remotePlayerDidCompleteChallenge:(GKChallenge *)challenge{
NSLog(@"remotePlayerDidCompleteChallenge");
}
- (BOOL)shouldShowBannerForLocallyCompletedChallenge:(GKChallenge *)challenge
{
return YES;
}
- (BOOL)shouldShowBannerForLocallyReceivedChallenge:(GKChallenge *)challenge
{
return YES;
}
- (BOOL)shouldShowBannerForRemotelyCompletedChallenge:(GKChallenge *)challenge
{
return YES;
}

关于ios - 哪个类用于实现 GKLocalPlayerListener 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19655737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com