Я пытаюсь добавить счет в конце игры в Game Center, но он ничего не добавляет в игровой центр.Я весь день ищу «ошибку», которую я сделал, но ничего не вижу?
Вот небольшой фрагмент кода, который мы используем.
.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>
@class GKLeaderboard, GKAchievement, GKPlayer;
int counter;
@protocol TopscoreDelegate <NSObject>
@optional
- (void) processGameCenterAuth: (NSError*) error;
- (void) scoreReported: (NSError*) error;
- (void) reloadScoresComplete: (GKLeaderboard*) leaderBoard error: (NSError*) error;
@end
@interface Topscore : UIViewController <NSObject> {
AVAudioPlayer *audioPlayer;
IBOutlet UILabel *count;
Topscore* Topscore;
}
- (IBAction)tweetTapped:(id)sender;
- (IBAction) subScore;
- (IBAction) showLeader;
- (void) reportScore;
@property (nonatomic, assign) id <TopscoreDelegate> delegate;
+ (BOOL) isGameCenterAvailable;
- (void) authenticateLocalUser;
@property (nonatomic, retain) Topscore *Topscore;
@property (nonatomic, retain) NSString* currentLeaderBoard;
@property (nonatomic, retain) UILabel *count;
@property(nonatomic, readonly, retain) NSDate *date;
- (void) reportScore: (int64_t) score forCategory: (NSString*) category;
- (void) reloadHighScoresForCategory: (NSString*) category;
@end
И файл .m выглядит так;У меня есть кнопка в XIB-файле, который подключен к IBAction Subscore
.я не получаю ошибки, но только несколько предупреждений.
PerformSelector may cause a leak because its selector is unknown
Это предупреждение в режиме онлайн;
[делегат executeSelector: селектор withObject: arg withObject: err];
.m
@interface Topscore ()
@property (strong, nonatomic) NSString *imageString;
@property (strong, nonatomic) NSString *urlString;
- (void)clearLabels;
@end
@implementation Topscore
@synthesize count, date, urlString = _urlString, imageString = _imageString, delegate, Topscore, currentLeaderBoard;
- (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];
}
else
{
[delegate performSelector: selector withObject: err];
}
}
else
{
NSLog(@"Missed Method");
}
}
- (void) callDelegateOnMainThread: (SEL) selector withArg: (id) arg error: (NSError*) err
{
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self callDelegate: selector withArg: arg error: err];
});
}
//..
+ (BOOL) isGameCenterAvailable
{
// check for presence of GKLocalPlayer API
Class gcClass = (NSClassFromString(@"GKLocalPlayer"));
// check if the device is running iOS 4.1 or later
NSString *reqSysVer = @"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);
return (gcClass && osVersionSupported);
}
- (void) authenticateLocalUser
{
if([GKLocalPlayer localPlayer].authenticated == NO)
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
{
[self callDelegateOnMainThread: @selector(processGameCenterAuth:) withArg: NULL error: error];
}];
}
}
- (void) reloadHighScoresForCategory: (NSString*) category
{
GKLeaderboard* leaderBoard= [[GKLeaderboard alloc] init];
leaderBoard.category= category;
leaderBoard.timeScope= GKLeaderboardTimeScopeAllTime;
leaderBoard.range= NSMakeRange(1, 1);
[leaderBoard loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error)
{
[self callDelegateOnMainThread: @selector(reloadScoresComplete:error:) withArg: leaderBoard error: error];
}];
}
//..
- (void) showAlertWithTitle: (NSString*) title message: (NSString*) message
{
UIAlertView* alert= [[UIAlertView alloc] initWithTitle: title message: message
delegate: NULL cancelButtonTitle: @"OK" otherButtonTitles: NULL];
[alert show];
}
- (void) scoreReported: (NSError*) error;
{
if(error == NULL)
{
[self.Topscore reloadHighScoresForCategory: self.currentLeaderBoard];
[self showAlertWithTitle: @"High Score Reported!"
message: [NSString stringWithFormat: @"", [error localizedDescription]]];
}
else
{
[self showAlertWithTitle: @"Score Report Failed!"
message: [NSString stringWithFormat: @"Reason: %@", [error localizedDescription]]];
}
}
- (IBAction) subScore {
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"01"];
scoreReporter.value = counter;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
NSLog(@"Failed: %i", counter);
} else {
NSLog(@"Succes: %i", counter);
[self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
}
}];
}
Пожалуйста, если вам нужно больше кода, просто спроситеme!
PS: Лидерборд появляется, но результаты добавления / добавления не добавляются после нажатия на кнопку (IBAction)