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 3273684
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:57:28+00:00 2026-05-17T18:57:28+00:00

i got a problem in [NSUserDefaults standardUserDefaults] in iOS4.0. I saved some states by

  • 0

i got a problem in [NSUserDefaults standardUserDefaults] in iOS4.0.

I saved some states by using [[NSUserDefaults standardUserDefaults] setObject:self.listData forKey:@"listData"]; in applicationDidEnterBackground: and applicationWillTerminate: methods. And i retrieved the data by using NSMutableArray *listData = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"listData"]]; in the viewDidLoad method.

I’m using sdk4.1 and simulator to test. The problem is: it does call the save method when my app enter the background. Since i want to know whether it’s really been saved, so i double click the home button to call the multitask stack and hold the home button, then use the minus icon to kill my app in the background. Then i enter the app again, but the data didn’t actually be saved.

Then i select the property Application does not run in background in the info.plist to see if it works in iOS3.0. And when i hit home button, it called the save method, then i enter the app, the data has been saved successfully.

So i’m wondering how the [NSUserDefaults standardUserDefaults] works in iOS4.0? How could i possibly save some data by using it in iOS4.0? Many thx!

  • 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-17T18:57:29+00:00Added an answer on May 17, 2026 at 6:57 pm

    To be more specific –
    [NSUserDefaults standardUserDefaults] is a pointer to a copy of the defaults file that is on the flash memory, not the defaults file itself. When you make changes, you are modifying this temporary copy only. It only gets written to flash memory when [NSUserDefaults synchronize] gets called. You should call this when your program exits.

    In reality your program probably works fine. The real issue is that killing the app from the multitasking bar does not call all the app exit functions, its just killing the process, much like Force Quit in OSX (probably exactly like a Force Quit actually).

    Your app works without multitasking because the default gets written in applicationWillTerminate and then [NSUserDefaults synchronize] is getting called for you in the normal exit process.

    If you want your preferences to survive a user initiated force quit, you should write your defaults when you change them, and put a synchronize call into the applicationDidEnterBackground

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

Sidebar

Related Questions

I've got a problem here with an MSI deployment that I'm working on (using
I've got a problem similar to link text I'm using XCode 3.2.4 (1708). After
Got a problem with ADOMD.NET 8.0, SQL2008 and our app. It isn't giving us
I got a problem like this (this is html/css menu): Eshop | Another eshop
I've got a problem with inheritance and generics. This is the code that illustrates
I've got a problem where I have a .co.uk domain of which I am
I've got a problem similar to,but subtly different from, that described here (Loading assemblies
On Vista, I got a problem with the application crash handler. Basically, if something
I've got this weird problem - I'm calling ChangeServiceConfig on a newly installed service
I have got the following problem since the server has safe mode turned on,

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.