customize an action of iphone home button to submit score in gamecenter

Member
Posts: 164
Joined: 2010.10
Post: #1
i have a button in my app a button that submit score to gamecenter and works. this is the code:

Code:
-(void)subScore{
GKScore *scoreRepoter = [[[GKScore alloc] initWithCategory:@"123456"] autorelease];
scoreRepoter.value=100;
[scoreRepoter reportScoreWithCompletionHandler:^(NSError *error) {
  if (error!=nil) {
      NSLog(@"errr submitting");
   }else
       NSLog(@"ok!");
}];

now i'd like to submit score before app is closed with home button. i thought to customize an action of home button (if it is possible) or perhaps i make the same line of code in viewDidUload...or something like that... will i be sure that that action will be performed before unloading the app? i should make that code in dealloc method? thanks
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #2
If you need to do stuff when your app deactivates use your UIApplicationDelegate's applicationWillResignActive method (and accept all caveats within).

But, you really should submit scores automatically and immediately after the game is over. People are likely to view the leaderboards right after a game ends, and if you submit when they hit the leaderboard button it's already too late.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #3
thanks for the answer.
my game ends when the home button is clicked so i had to use applicationWillResignActive, but what does "(and accept all caveats within)." mean?
the app will show popup or something like?
can i submit while the app is starting?
thanks
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
The home button is not supposed to end anything... the app's supposed to pick up right where it left off when it's reopened.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #5
(Nov 28, 2011 06:13 AM)sefiroths Wrote:  what does "(and accept all caveats within)." mean?

It means applicationWillResignActive only gives you a few seconds to save state and clean up, and network access might be cut off before you get a chance to send anything. That's why you really should send scores as soon as the player hits your game over screen.

It sounds like you might be jumping into this without a real understanding of how iOS works. I hate to say "RTFM" but if you're just starting out you really should (at least) read the Programming Guide: http://developer.apple.com/library/ios/#...ction.html
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #6
i'm a beginner.
i have readed all manuals, ton of documentation.
i remember a part, sometimes i have it not really clear, sometimes i forgot.
i thought that the best way to remember and learn is to read all documentation, (or what i need at the moment), then try to put in practise.
i ask only if i don't remember and don't find the documentation relatively to what i'm doing

thanks for all the helpful and kind answers
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
I think you should try actually using a device before you try to design software for it!
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #8
ok thanks for the tip!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  gamecenter hidden achievement is visible sefiroths 0 1,944 Nov 7, 2012 12:20 PM
Last Post: sefiroths
  customize uialertview sefiroths 1 3,985 Aug 10, 2012 02:02 AM
Last Post: sefiroths
  skinning gamecenter UI sefiroths 6 10,573 Aug 17, 2011 10:09 AM
Last Post: sefiroths
  glutBitmapChar and my score. mikey 2 2,666 May 15, 2009 10:08 AM
Last Post: mikey
  Left mouse button causes moueup event despite button still being pressed. QuestingCordiial 28 11,475 Jun 21, 2008 03:18 PM
Last Post: AnotherJake