High score system iphone game - iphone

I have made a simple class that allows me to submit scores to my online highscore-system, but I am wondering what I would do if there is no internet connection availible. I save the scores in a plist, but it doesn't get synchronised there, that happens after a player gets a new highscore, after a game thus. If there is no connection with the internet, the score won't get submitted.
My question is : "How can I make sure that the highscores are synchronised when there is a connection availible?"
Thanks in advance,
Joe

The last Cocos2d game I wrote I used Steffen Itterheim’s GameKitHelper class for this to great effect.
Also see:
Integrate Gamecenter in cocos2d game
Synchronizing Offline Game Center Achievements and Scores
You could probably adapt one of these for your own high-score system, but it does beg the question "why not use game center?"

You can keep a record of the score upload status (with date+time, so you can have multiple scores) in a file and check it on startup for any scores that weren't synchronized.

I don't know anything about iPhone development yet, but on a logic level, why don't you have a boolean flag set to false stating that it never was synced online yet. Then when the game starts, check the flag and if the flag is false and internet is available update the score data. You can either then set the flag to be true, or delete the value out of the plist.

Related

Stop Game Speed Hack

I have an app where I open a HTML5 game in WebView, its a single player game where we match 2 players and who ever scores more wins the game. This has a time limit. There are users who use speed hack X8 Speeder for one. I am trying to find how do I avoid this.
How do I detect if a particular app is installed on the phone. Even if they change the app name
How do it detect if my APK has been patched or modified.
Any help would be great.
Regards
Mitsy
Off the top of my head, I'd try to verify game sessions on the backend. When game completes, your app sends the complete log of what happened to your server which then analyzes it. If the log was generated by a script (like this, for example: https://x8speeder.com/?p=77), it will have very repeated and detectable sequences. You can then discard this score and not put it on the leaderboard.

OpenFeint, Game Center and multiple users

I'm about to add highscore support to my mobile game and I have a basic understanding problem with leaderboard services like OpenFeint or Apples Game Center:
Suppose I'm logged in to OpenFeint and/or Game Center with my account. Then a pal of mine wants to play, I hand him my device and he gets the best score ever. Is there any way he can get his score listed under his name now? My understanding is that he can't, because when the game is over the score is saved, and it is automatically saved for the current account, which happens to be mine at that moment. Tough luck.
This would mean that if I play the game with my pal in turns we would constantly have to log in and out from both services after each game to get it right in the case that one of us gets a highscore. That seems a bit awkward...
Do I overlook something or is this just the way it works? Or do I have to take care for this situation as a developer? Or do the OpenFeint/GameKit SDKs handle this automatically somehow?
I don't know about Open Feint, but at least for Game Center I think the answer to your question is: Yes, that's just the way it works. Even if you know the Game Center id's for both you and your friend, you don't have the ability to save stats for anyone but the logged in game center player.
It does seems possible that they could have supported this use case, to allow more than one player to be "signed in" on a given device, and then the game could just present a "PlayerA", "PlayerB" button to choose who's playing, instead of having to run the Game Center app to do the switch. But I imagine this use case wasn't a super high priority. (They'd rather have each of you playing on your own devices. And in fact some services like ScoreLoop keep things simple by enforcing a single player per device, period.)

How to sync score when game center is not available?

imagine there is no internet connection when user is playing. The score cannot be submitted to game center. However I save the highscore on the phone using NSUserDefaults too.
So when the user plays next time and is connected to game center should I sync this score he achieved playing "offline"?
Is that a good practice?
Per the Apple Game Center docs, the answer is YES.
Make Sure Your Game Sends Data Again After a Network Failure
When you implement leaderboards or achievements, your game reports a
player’s scores or achievement progress to Game Center. However,
networking is never perfectly reliable. If a networking error occurs,
your game should save the Game Kit object and retry the action again
at a later time. Both the GKScore and GKAchievement classes support
the NSCoding protocol, so your game can archive those objects when it
moves into the background.
Set up a cache that keeps your score data (I use NSUserDefaults) to preserve data between sessions, and every so often (like, each time the user enters the app) test to see if Game Center is reachable, and if so, upload your cached scores. Let me know if you need any code - this post is pretty old, so I won't be surprised if no one ever answers :)
Also per the Apple docs for iOS 5.0 and later network error related issues are handled by a background reporting task so the developer does not need to write anything to handle this if not supporting previous iOS versions.
(from GKScore Class Reference for method reportScoreWithCompletionHandler:)
If the error is a network error and your game is running on iOS 4.3 or earlier, your game should periodically attempt to report the progress until the score is successfully reported. On iOS 5.0 and later, the background reporting task automatically handles network errors on your game’s behalf.
I am not sure what is supposed to happen if no one is logged into Game Center at all though (no network related/ submission issues) when a high score is achieved and then someone logs in later. In that case no GKScore object can even be created because there is no authenticated player and so there is no way to know who actually achieved the score whenever the next person logs into Game Center. Seems handling logged in (even without a network connection temporarily) is best practice but if no one is logged in at all and a high score is gained then it's just tough luck because it is not known who earned it, other than saving it as a device high score. If anyone handles that case then please tell.
Good question.
In my point of view, if a user is offline and is still playing, the score he/she scores should be saved locally. And when he/she again appears online, the offline score shouldn't be submitted online. Because if offline score is submitted, the purpose of making the game online is defeated.

What are some ways I can sync iPhone Game data between multiple devices?

From the Getting Started with Game Center doc
A player might have the same Game Center enabled game loaded on multiple devices. If your
app has reported progress on an achievement from one device, note that the same
achievement progress data will be provided by Game Center on other devices where the user
plays your game. However, other game state maintained by your app may not be in sync and
should be handled accordingly.
I'm relatively new to iOS development and about to begin researching how to sync local game state data (i.e. which levels the player has completed, which levels the player is currently on, etc.) between the different hardware (iPhone, iTouch, and iPad) running my game and I was hoping I could get some insight from the SO users on some good ways to do this. Do I need to build a web service for this? Can iTunes be used to sync this data? Is there an API specifically built for this?
Thanks for your wisdom!
I think using a web serivice and making a JSON post and request would be a good route.
One suggested method by Apple is to use the Application Preferences, which is backed up by iTunes when the user syncs the phone.
I use NSUserDefaults for this and and it works great!
iCloud is your ticket

iPhone OS: implementing your own achievements, how do I do it?

I'm working on a game where really the only game part is (at least right now) that the user can unlock achievements as she does various things throughout the game. I have a database that can keep track of certain user actions and record how many times a user does something but I'm having trouble figuring out the best way to architect the app so that I have to do the least amount of work. Kind of suck with the timing because gamecenter is not ready and it seems like openfeint is changing gears, but maybe I'm wrong. I'd prefer to do everything "in house" if it is not too ridiculous. looking for suggestions.
One of the parts I'm having the most trouble figuring out is how to manage the state of all the achievements. NSuserdefaults vs. core data vs. a flat data file.
Also is there anyway to send a notification if a core data field reaches a certain amount?
Thanks,
Nick
Are you keeping the achievements on the device only, or also on the server? On the device, there is no reason not to use Core Data.
Using Core Data, you could use KVO on your model properties to monitor when certain values reach a new achievements.