Game Center Challenges in iOS 10
Asked Answered
D

1

17

I've implemented Game Center features like achievements and leaderboards, and now I'm working on the challenges. I was under the impression that I didn't have to add any additional code - if I had achievements or leaderboards, players would be able to send challenges to their friends. But now, in iOS10, you no longer have the ability to add players as friends - the challenges are handled through iMessages. The problem is - I don't see that feature anywhere in the GKViewController screen. If you select an achievement/leaaderboard score, you can tap on 'Challenge Friends', but it only suggests the players you already have in your friends list rather than in your contact list. Apple has also deprecated GKChallengesViewController, so I'm not sure where to look on how to do this.

Does anyone know how to add the iMessage Challenges feature to Game Center in iOS 10?

Update: I have seen that this feature lives within the GKMatchmakerViewController, but that seems to be for multiplayer type things. I'm still not sure how to use this to just send challenges.

Diplopod answered 3/1, 2017 at 20:3 Comment(1)
all working functions you can find here. developer.apple.com/reference/gamekitSpiegel
D
2

From the Apple Docs:

Issuing a challenge does not display a user interface to the player issuing the challenge; this is code you need to implement yourself.

There are also a few examples on how to issue challenges and how to find players you can invite, such as:

- (void) challengePlayersToCompleteAchievement: (GKAchievement*) achievement
{
    [achievement selectChallengeablePlayers:[GKLocalPlayer localPlayer].friends withCompletionHandler:^(NSArray *challengeablePlayerI, NSError *error) {
        if (challengeablePlayers)
        {
            [self presentChallengeWithPreselectedPlayers: challengeablePlayers];
        }
    }];
}

...or:

- (void) challengeLesserMortalsForScore: (int64_t) playerScore inLeaderboard: (NSString*) leaderboard
{
    GKLeaderboard *query = [[GKLeaderboard alloc] init];
    query.leaderboardIdentifier = leaderboard;
    query.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
    query.range = NSMakeRange(1,100);
    [query loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
        NSPredicate *filter = [NSPredicate predicateWithFormat:@"value < %qi",playerScore];
        NSArray *lesserScores = [scores filteredArrayUsingPredicate:filter];
        [self presentChallengeWithPreselectedScores: lesserScores];
    }];
}

By the looks of it you still can only invite players that are already part of game center, i.e. no arbitrary "contacts" from the contact list (which makes sense), but this is only an assumption.

Discontinuity answered 10/2, 2017 at 18:40 Comment(1)
Thanks for the post. I was under the assumption from the WWDC 2016 video that challenges could be sent via your contacts list rather than your Game Center friends list, which can no longer be added to.Diplopod

© 2022 - 2024 — McMap. All rights reserved.