Store a value beyond applicationWillTerminate
I have searched in Apple’s iOS dev center but couldn’t find anything quite right. Here’s my problem:
I have an app that uses CoreData with several entities. The data is dynamically updated via a server. Now
checkForUpdates is called every time the app becomes active, but is only executed when a certain amount of time passed since the last update.
checkForUpdates is finally executed it updates all the content, checking for each object if the version on the server is a more recent one according to the last time an update was done.
I have a local variable in my
Updater class of type
NSDate that holds the last time an update was successfully done. I need to be able to store this value somehow and somewhere beyond termination of the application.
I was wondering what would be the most cost-effective way memory-wise and also in terms of performance. Looking at the iOS dev center I first thought about application preferences, but since it is only a single value I thought there would be an easier way. Sorry if this is really easy but I’m new to objective-c and iOS programming.
Any help would be appreciated! If more information is needed feel free to comment below.
edit: Would it be a good idea to simply create a new entitiy with an
NSDate attribute and to simply keep the
lastUpdateTime variable in my database?
- Locking the Fields in MFMailComposeViewController
- How to get hash fragment of URL from UIWebView
- Is it possible to get a crash log due to expiration of provisioning profile?
- AWS S3 HEAD request not returning 404 when file doesn't not exist
- how to debug EXC_CRASH (SIGTRAP)
- Can you disable rotation globally in an iOS app?
3 Solutions Collect From Internet About “Store a value beyond applicationWillTerminate”
Sounds like you want the NSUserDefaults storage. It’s used like a dictionary, but persists:
[[NSUserDefaults standardUserDefaults] setObject:myDate forKey:@"LastUpdateTime"];
NSUserDefaults to store the last update time.
When your Updater is successful, write the success time to your apps defaults, that way it is accessible on your next launch, and you can call this anytime you to.
Swift 2.X Version
NSUserDefaults.standardUserDefaults().setObject(NSDate(), forKey: "Last_Modified")
- XCode unit testing
- iOS setContentOffset not working on ipad
- Firebase Phone number authentication Error
- Configuring Cocoapods with an existing static library and iOS application
- Why does Xcode successfully build & copy my application, but won't launch it?
- Choose a different simulator in Xcode 6
- Shuffle NSMutableArray
- Passing Data from App delegate to View Controller
- MKPinAnnotationView custom Image is replaced by pin with animating drop
- Get the NSString height
- passing data using delegates between viewcontrollers without any navigation controller connection
- Swift link Image from Parse array using segues to secondViewController
- UIImageView with big image. issue
- How can we change the font of tableview header?
- AWS ExpiredTokenException after app relaunch