Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Game Center: Creating Lifetime Achievements
    text
    copied!<p>I'm trying to add a Lifetime achievement to my iOS app. That is, how many times the user performed the single action since he played the game for the first time. In other words, how many kills he got since... ever. I'm using the code based on the one provided by Apple:</p> <p>.h file:</p> <pre><code>int64_t lifetimeScore; IBOutlet UILabel *lifetimeScoreLabel; </code></pre> <p>.m file:</p> <pre><code>- (IBAction) increaseScore { self.lifetimeScore = self.lifetimeScore + 1; lifetimeScoreLabel.text = [NSString stringWithFormat: @"%ld", self.lifetimeScore]; // Saving the Score: NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; [defaults setInteger:lifetimeScore forKey: @"Score"]; [defaults synchronize]; [self checkAchievements]; } - (void)viewDidLoad { [super viewDidLoad]; // Loading the Lifetime Score: self.lifetimeScore = [[NSUserDefaults standardUserDefaults] integerForKey: @"Score"]; lifetimeScoreLabel.text = [NSString stringWithFormat: @"%ld", self.lifetimeScore]; (...) } </code></pre> <p>I works great, no warnings, but each time I close the app, deletes it from the Multitask bar and open the app again, the lifetimeScore goes back to zero. I'm trying to save the int_64 using NSUserDefaults but so far I can't make it work... any ideas?</p> <p>EDIT: The code was fixed and now it's working 100% in case anyone wants to use it. The complete source code can found here: <a href="http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-game-center-achievements-and-leaderboards-part-2/" rel="nofollow">http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-game-center-achievements-and-leaderboards-part-2/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload