i have a button in my app a button that submit score to gamecenter and works.
this is the 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
You can’t customize behaviour of Home button directly, but iOS provides some methods in your application’s delegate, by which you can control lifecycle of the application.
Method called right before the application goes to background is
applicationWillResignActive:in your application’s delegate (usually this method is located inAppDelegate.mfile).I think you can get needed effect by calling your method like that:
Also please note that iOS has time limit of execution for this method: you must do all saving-the-game work in less that five seconds or your application will be killed.