Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3321848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:06:45+00:00 2026-05-17T23:06:45+00:00

While my iPhone app is running I store some data (NSStrings) in the NSUserDefaults.

  • 0

While my iPhone app is running I store some data (NSStrings) in the NSUserDefaults. I’m storing the high score for a game just fyi. When I double-tap the home button and kill the app the values I store in NSUserDefaults are often not there when I restart the app. Why is this happening?

The code I’m using was working fine in all the pre-multitasking OSs (3.0 etc). From reading/searching the net it looks like doing [NSUserDefaults standardUserDefaults] synchronize]; could help. Any thoughts?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:06:45+00:00Added an answer on May 17, 2026 at 11:06 pm

    Killing an app from the taskbar when it’s suspended just sends it the SIGKILL message; no graceful shutdown happens.

    If you’re backgrounding and then killing the app, you might not be getting the user defaults synchronized (written to disk) before the app dies, which happens by itself on an internal timer usually, but if you’ve written to the defaults and then the thing gets suspended before the auto-synchronize happens, that could explain this behavior.

    Put this (as you note):

     [[NSUserDefaults standardUserDefaults] synchronize];
    

    in your -applicationDidEnterBackground handler in the app delegate. That way, even if the app dies or is killed while it’s in the background, you know the defaults have been written.

    As a defensive practice, I generally explicitly call synchronize on the defaults object every time I write state that I consider critically important.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running into a crash issue while developing an iPhone app with Core Data.
I am using the Wikitude API in my iPhone app. But while running the
I am new to iPhone app development and have a question about storing data.
I am using sqlite database for iphone app. but its crash on while loop
I added a launch image to my iPhone app in Xcode, but after while,
I have a Core Data app that will end up being an iPhone/iPad universal
I've noticed for a while that the iPhone app I'm developing takes a very
I am in the process of submitting an iPhone app to the App Store.
I'm making a simple high scores database for an iPhone game using Amazon's SimpleDB
i have a problem while building and running an iphone application.Im using xml parsing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.