How to get total No. of players from Leaderboard - ios

Is there any way I can get how many player has played my game and successfully reported the score on Leaderboard?
I am currently working on Marmalade for iOS, so I'd prefer if you can let me know the solution in Marmalade. But if not possible, kindly let me know the solution at least in Objective C.

Finally found the solution after searching in the marmalade example. Following is the steps for to get the total count -
1.First you need to authenticate the player to gamecenter, it's like Login. THe authentication method is -
s3eIOSGameCenterAuthenticate(AuthenticationCallback, NULL);
2.Next we need to load the scores from the leaderboard
s3eIOSGameCenterLeaderboardLoadScores(leaderboard,loadScoreCallBack);
3.Now in the callback method i.e. loadScoreCallBack, you will get the TotalCount.
void loadScoreCallBack(s3eIOSGameCenterLoadScoresResult* result)
{
int TotalCount= result->m_ScoreCount;
}

Related

Game Center Matchmaking Custom Invites

I'm sure theres a 'simple' answer to this, but I've been having a difficult time finding it.
I've created an iOS card game that works in game center. At the moment, it determines the online players automatically and works fine.
What I want to do is have the user invite their game center friends to play. The documentation isn't really helping me.
I'm doing my project in swift, and I feel like I'm dealing with deprecated items and old documentation here?
I've managed to get the users list of friends and then I assume I need to instantiate a matchmaker with that list of friends.
What I'm stuck at, is trying to implement the "RecipientResponseHandler" code as per apple's guidelines:
request.recipientResponseHandler = ^(GKPlayer *player, GKInviteeResponse response)
{
[self updateUIForPlayer: player accepted: (response == GKInviteeResponseAccepted)];
};
Question 1: First of all, What does the ^ symbol represent in the swift language?
Question 2: XCode doesn't seem to like the * symbol in the arguments...I've tried doing things like...
request.recipientResponseHandler = (player: GKPlayer, response: GKInviteeResponse){
print("Do codeStuffHere")
};
But, I can't find a way of wording this that XCode will allow...
Question 3: How can I write this response handler to get it to work?
Question 4: Also,to listen for invites, I need to implement the GKLocalPlayerListener protocol...Anything else?
Question 5: I feel like I'm missing something glaring?
I've been learning on my own, and sometimes it takes a while to understand concepts without any direction, so please go easy on me internet. I'm just starting to understand completion handlers and closures...
Thanks in advance for any help.
What does the ^ symbol represent in the swift language?
XCode doesn't seem to like the * symbol in the arguments.
That's because that code is written in Objective-C, not Swift.
I'm assuming you're looking at the documentation for GKMatchRequest (update as of Jan 2023: It seems Apple has removed the code listing from this page at some point).
If so, then yeah, Apple just hasn't gotten around to updating all their documentation to use Swift instead of Objective-C (even on pages where the language selected is Swift, like this one).
Here's the Swift equivalent of that entire code listing:
func invite(friends: [GKPlayer]) {
let request = GKMatchRequest()
request.minPlayers = 2
request.maxPlayers = 4
request.recipients = friends
request.inviteMessage = "Your Custom Invitation Message Here"
request.recipientResponseHandler = { player, response in
self.updateUI(for: player, accepted: response == .accepted)
}
}
func updateUI(for player: GKPlayer, accepted: Bool) {
// update your UI here
}
For question 4, be sure to register the GKLocalPlayerListener and only register once, for example:
GKLocalPlayer.local.register(self)

iOS 11.4 not asking Privacy Usage ( Privacy - Motion Usage Description has been set )

I'm stumped, iOS 11.4 ( 15F79 ), iPhone 6. Cannot get the App to Ask for Motion Data. info.plist has been set via the editor and double checked via the info.plist open in textWrangler, Also deleted key and saved via textWrangler.
<key>NSMotionUsageDescription</key>
<string>This app needs your Phones motion manager to update when the phone is tilted. Please allow this App to use your phones tilt devices</string>
I have deleted then reinstalled the app about 10 times. I have restared the phone 5 times. I have checked through settings and my app does NOT show up in Privacy-Motion and Fitness or anywhere else in settings. I am using a free developer account, maybe that has something to do with it?
I created a new Xcode game template and changed nothing apart from importing CoreMotion and this code
**** Edited, sorry I forgot to say I had started the instance, just forgot to put it here, just in case someone thinks that's the problem ************
let motionManager = CMMotionManager()
override func didMove(to view: SKView) {
motionManager.startDeviceMotionUpdates()
if motionManager.isDeviceMotionActive == true {
motionManager.accelerometerUpdateInterval = 0.2
motionManager.startAccelerometerUpdates(to: OperationQueue.current!, withHandler: {
(accelerometerData: CMAccelerometerData!, error: NSError!) in
let acceleration = accelerometerData.acceleration
print(accelerometerData)
} as! CMAccelerometerHandler)
}else{
print(CMMotionActivityManager.authorizationStatus().rawValue)
}
which prints a 0 ( an Enum - case not determined ) to the console.
In my actual app it was a 3 ( same Enum - case Denied ).
As I've said, I have uninstalled, reinstalled, edited plist via Xcode and text wrangler ( a code editor ) , tried different versions of the code above, tried the code in different places ( in did move to view, in class )tried code off apple docs. etc.... I haven't been asked the NSUsage question and the App keeps crashing.
I have looked for ways to get the Alert fired up, As in CLLocationManager.requestWhenInUseAuthorization() but I cannot find a comparable CMMotion version ( I don't think there is one. ) I have created a new swift file , imported Foundation and CMMotion and just put that code there, But still no Alert asking for Motion Data.
I tried a single view app template instead of a game template thinking that might be the issue, Nope.
What do I do?
Any help Appreciated. Thanks
You are confusing two related but different classes.
CMMotionManager gives access to accelerometer, magnetometer and gyroscope data. It does not require any user permission as this information is not considered privacy related.
In your else clause you are checking the authorisation status of CMMotionActivityManager. This object reports the device motion type (walking, running, driving). This information is considered privacy related and when you create an instance of this class and request data from it, the permissions alert is displayed.
The reason your else is being triggered is because you are checking isDeviceMotionActive; this will be false until you call startDeviceMotionUpdates, which you never do. Even if you used isAccelerometerActive you would have a problem because you call startAccelerometerUpdates in the if clause which will never be reached.
You probably meant to check isAccelerometerAvailable. If this returns false then there isn't much you can do; the device doesn't have an accelerometer.
Update
It doesn't make sense to check isDeviceMotionActive immediately after calling startDeviceMotion:
You know it's active; you just started it
I imagine the start up takes some time, so you could expect to get false if you check immediately.
Apple recommends that you do not have more than one observer in place for each motion device type, so the purpose of check the is...Active to ensure you don't call start... again if you have already done so.
If you only want gyroscope data then you don't need to call startDeviceMotionUpdates at all.

AdMob - RewardVideo not giving out reward after video is finished

I have AdMob installed in my sprite kit game and I'm using mediation to get reward videos for the user so that they can earn in game coins but when they watch the video it plays but doesn't give the reward. Now when I try and type out the function it doesn't show a function that gives the reward.
but when I copy and paste it xcode doesn't give me an error but it still doesn't give me the reward.
what is the problem and how can I fix it?
EDIT
I show the reward video like so:
func showRewardVideoAd() {
if rewardVideoAd.isReady {
let vc = self.scene?.view?.window?.rootViewController
rewardVideoAd.present(fromRootViewController: vc!)
rewardVideoAd = createRewardAd()
}
}

Implement my own a custom GKTurnBasedMatchmakerViewController

I'm sure there are questions similar to this, but I couldn't find an example. I'm trying to recreate the apple GKTurnBasedMatchmakerViewController for my turn based game with my own custom interface for my turn based iphone game. I'm having trouble getting all the options to display correctly so I was hoping someone had a working example. My current code is this:
-(void)getCurrentGamesFromServer {
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error) {
if(matches){
for (GKTurnBasedMatch *myMatch in matches) {
//this is, I believe, also where we need to consider invitations. available instance methods provided by GC are: acceptInviteWithCompletionHandler and declineInviteWithCompletionHandler
if(myMatch.status == 1){ //ongoing game
if([myMatch.currentParticipant.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]){ //if it's my turn
//here we need to populate the table by adding our matches to mcurrentgamesarray. after all the matches have been added, reload the tableview
NSLog(#"active game that is my turn");
[self.mCurrentGamesArray addObject:myMatch];
}
else{
NSLog(#"other turn or an invite from another player waiting to hear from you");
}
}
}
}
[_mCurrentGamesTableView reloadData];
}];
}
As you can see, the only games I'm grabbing right now are games where the status is 1 (ongoing game) and the current participant ID is my ID.
to get games that were not my turn, I tried doing games where it was not my ID, but it included invites with it and I couldn't figure out how to separate them out.
Basically, I'd like to have a section of games where it is my turn, a section where it is not my turn but games are still active, a section of completed old games, and a section for invites. does anyone have a working example, or a page they can send me to that explains the best practices for what I'm trying to do? Thanks for your help.

Gamekit / gamecenter random matchmaking programmatically

I am trying to implement random matchmaking programmatically with my own custom userinterface.
I'm kinda stuck..
using this code found at the apple site I can create a match without problems
- (void)findProgrammaticMatch
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
[GKTurnBasedMatch findMatchForRequest: request withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
{
if(error)
NSLog(#"ERROR");
if (match) {
NSLog(#"STARTING MATCH");
}
}];
}
and if I do match.participants.count I get the number 2...
but one participant is me and the other is null
What ive done to test is create 2 sandbox accounts and I ran the same code with my other game center account, and I got a new game created,.. but it didnt match them for some reason.. am I missing something?
ive been looking for examples on google, but I can't seem to find any.. if any of you know anywhere I can find some examples, I would be most grateful
Well, you might be missing out an essential point in turn based match making. When the user starts an automatch if he is not connected to an existing match it starts a fresh game and user takes the first turn. Only after HE COMPLETES HIS TURN, other users can connect to this game. So if you are making a 2 player match: one user should start a fresh game with the other user being null at that moment and the other user should connect to this existing game after the first one finished his turn (endTurnWithMatchData called)
This is not very clear in documentation (I despise the gamecenter documentation, unclear & incomplete) but it is the case for sdk 6. I think it will change in the near future.

Resources