I have an app that uses [NSUserDefaults standardUserDefaults] to store session information. Generally, this information is checked on app launch, and updated on app exit. I
iOS 8 introduced a number of behavior changes to NSUserDefaults
. While the NSUserDefaults
API has changed little, the behavior has changed in ways that may be relevant to your application. For example, using -synchronize
is discouraged (and always has been). Addition changes to other parts of Foundation and CoreFoundation such as File Coordination and changes related to shared containers may affect your application and your use of NSUserDefaults
.
Writing to NSUserDefaults
in particular has changed because of this. Writing takes longer, and there may be other processes competing for access to the application's user defaults storage. If you are attempting to write to NSUserDefaults
as your application is exiting, your application may be terminated before the write is committed under some scenarios. Forcefully terminating using exit(0)
in your example is very likely to stimulate this behavior. Normally when an application is exited the system can perform cleanup and wait for outstanding file operations to complete - when you are terminating the application using exit()
or the debugger this may not happen.
In general NSUserDefaults
is reliable when used correctly on iOS 8.
These changes are described in the Foundation release notes for OS X 10.10 (currently there is not a separate Foundation release note for iOS 8).