issue submitting score to a leaderboard - iphone

i have enabled Game Center in my itunes connect for my app.
In my game center, i have created a leaderboard named "Level 1" with its id "level1", integer.
In my game, i try to submit a score like this:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:#"level1"] autorelease];
int64_t score1 =scr;
scoreReporter.value = score1;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(#"Submit failed");
}
else {
NSLog(#"Score Submited");
}
}];
[pool release];
but i get a submit failed; i've created the leaderboard about 30-40 mins ago, could it not be enabled yet by apple? if else, i don't know what i'm doing wrong.
Here is my error:
Error: Error Domain=GKErrorDomain Code=6 "The requested operation
could not be completed because local player has not been
authenticated." UserInfo=0x1ed4d4a0 {NSLocalizedDescription=The
requested operation could not be completed because local player has
not been authenticated.}
btw i have internet access on my iphone and am connected on my phone to an apple account

Wasn't authentificated in game center, now it works!
Example from Game Center Programming Guide:
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
// Player was successfully authenticated.
// Perform additional tasks for the authenticated player.
}
}];
}

Related

iPhone App Crash with error [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:]

I have an iPhone App in the app store which is using Touch ID. If Touch ID is enabled, the user is authenticated with it, else user needs to enter his PIN to login to the application.
After IOS 10.1 release, when I checked the crash report, the crash count has increased. From the crash report, it is pointing on [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] and when I opened the app in Xcode, it is focussing on [self dismissViewControllerAnimated:YES completion:nil];.
The code I have written is as below:
-(void) showTouchIDAuthentication{
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = #"Authenticate using your finger to access My Account Menu.";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"User is authenticated successfully");
[self dismissViewControllerAnimated:YES completion:nil];
} else {
}];
}
}
When I tested in iPhone 6, IOS 10, everything is working fine. Don't know how to simulate the issue.
Can anyone please figure out if I am missing something? Please help me out in resolving this crash issue.
Usually completion handlers are not running on main thread. All UI related stuff must be done on main thread (including dismissing a view controller).
I suggest to add the dismiss line on a main thread block like this:
-(void) showTouchIDAuthentication{
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = #"Authenticate using your finger to access My Account Menu.";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"User is authenticated successfully");
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[self dismissViewControllerAnimated:YES completion:nil];
}];
} else {
}];
}
}

Leaderboard "No Items"

I'm trying to implement GameCenter to my app.
This is to show me the GameCenter LeaderBoard but it's shows me: No Items.
-(IBAction) ShowLeader{
GKGameCenterViewController* gameCenterController = [[GKGameCenterViewController alloc] init];
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
gameCenterController.gameCenterDelegate = self;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
The user is authenticate and that's show up when i connect.
when i report score in my GameViewController:
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKScore* scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier:#"GameHighScore"];
scoreReporter.value = HighScoreNbr;
scoreReporter.context = 0;
// NSArray *scores = #[scoreReporter];
[GKScore reportScores:#[scoreReporter] withCompletionHandler:^(NSError *error) {
if (error) {
NSLog(#"error: %#", error);
}
printf("no error: ");
}];
}
This shows me no error so i suppose it works.
I already tried with 2 accounts since i saw that on other answer but didn't help.
If you need any more info please comment.
Thanks.
I found out myself after reading and viewing tones of video.
if that can help someone who as the same problem:
you need to had your BundleID from Itunes connect to your xcode5 info playlist.
then it should work.
Hope it helps ;)
This can also happen if gamekit is missing from Required device capabilities in your plist.

Problems With Game Center

Just finished my first iOS game (mostly). Its all ready to go, just need to link in Game Center. This however, is proving to be ...annoying. My App is all registered on iTunes Connect, and all the Game Center code is taken directly from Apple. So why is NONE of this working?
First: authentication always fails;
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *loginVC, NSError *error) {
if ([GKLocalPlayer localPlayer].authenticated) {
// authentication successful
}
else if (loginVC) {
// player not logged in yet, present the vc
[self presentViewController:loginVC animated:YES completion:nil];
}
else {
// authentication failed
}
};
With error "The requested operation has been cancelled"
As a corollary, trying to present a game center vc in the future yeilds a "Player is not signed in message"
Second: this
GKScore *score = [[GKScore alloc] init];
if (score) {
score.value = self->selectedScore;
NSArray* scoreArray = [[NSArray alloc]initWithObjects:score, nil];
//score.category = #"High Scores";
UIActivityViewController *avc = [[UIActivityViewController alloc]
initWithActivityItems:scoreArray applicationActivities:nil];
avc.completionHandler = ^(NSString *activityType, BOOL completed) {
if (completed)
[self dismissViewControllerAnimated:YES completion:nil];
};
if (avc)
[self presentViewController:avc animated:YES completion:nil];
}
yeilds a 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
What am I fundamentally doing wrong? Thanks to anyone who can offer any help.
Try to log out/in in the Game Center application with your test user account.
Check this answer: https://stackoverflow.com/a/4420457/89364

Server error when trying to report Achievement to GameCenter

When using the code from Apple,
- (void) reportAchievementIdentifier: (NSString*) identifier percentComplete: (float) percent
{
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];
if (achievement)
{
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError *error)
{
if (error != nil)
{
NSLog(#"problem with reporting");
NSLog(#"%#",[error localizedDescription]);
// Retain the achievement object and try again later (not shown).
}
}];
}
}
I get the error:
The requested operation could not be completed due to an error communicating with the server.
I have verified the user and it seems to register that i have played the game, but it cannot record the achievement. Any ideas?
Try using the reachability sample application from Apple to find out if the iPhone is connected to the internet via wifi or 3G. http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
It takes a few minutes for the Achievements from itunesconnect to propagate to the server.
Just try a little later, and it will not hurt to deinstall and install app again either.

iPhone gamecenter submitting highest score?

I am using below function to submit score to game center. How to modify below code so that I can send the score only if it is highest than already submitted score? And I dont want to maintain the scores locally. Any help?
- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler: ^(NSError *error)
{
[self callDelegateOnMainThread: #selector(scoreReported:) withArg: NULL error: error];
}];
}
Thanks.
Edit : I just found that it is handled by the game center only... Only the top score will displayed on the gamecenter app.
You can retrieve the previous score using
GKLeaderboard *query = [[GKLeaderBoard alloc] initWithPlayerIDs:[NSArray arrayWithObject:yourPlayerId]];
if (query != nil)
{
[query loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
if (error != nil)
// handle the error.
if (scores != nil)
// process the score information.
}];
}
Get more information on Apple GameKit Programming Guide