iOS 10, NSUserDefaults Does Not Work
I just had the same problem. There seems to be an issue with NSUserDefaults
when first running the iOS8 or 9 simulator and then the iOS10 simulator.
Rebooting the mac solved the issue for me.
Swift 3 / iOS 10 / TodayExtension - UserDefaults always returns nil
I partially solved my problem.
I have completely remove Xcode and all the settings (caches files etc...),
then I have removed the "Team" part in the suite name.
Now I have like a warning in the Xcode console but I can retrieve my notes in my TodayExtension. Piouf !
I still have the problem for WatchKit Extension. I'm not sure but I think that I have read that UserDefaults even with App Groups are not shared with Apple Watch Extensions.
But Apple write in their documentation "Also, iOS automatically forwards a read-only copy of your iOS app’s preferences to Apple Watch. Your WatchKit extension can read those preferences using an NSUserDefaults object, but it cannot make changes directly to the defaults database."
So I don't know why I cannot retrieve my notes from my Apple Watch.
At least I have solved my first problem. If anybody has the same.
Using NSUserDefaults with Xcode 8 and iOS 10
NSUserDefaults
has been renamed to UserDefaults
. standardUserDefaults()
has been renamed to standard()
.
let defaults = UserDefaults.standard
This now works.
Pre-release documentation link.
iOS 10 Today extension can't read shared user defaults any more
It sounds like the issues is that your Entitlements file is missing the relevant line.
To diagnose where the issue is, start with your build settings:
- Under
Code Signing Entitlements
there should be a file listed - Open that file and ensure that it has the
App Groups
key with the value that matches yourkSharedGroupIdentifier
- Ensure that the file is not marked read-only (this would potentially cause the "fix" to not work correctly)
- Verify that all of the following match:
- kSharedGroupIdentifier in both apps
- kSharedGroupIdentifier and the value in your entitlements file for
App Groups
Next, we can narrow the issue down to the specific key or the entire preferences domain as follows:
NSUserDefaults *sharedPrefs = [[NSUserDefaults alloc] initWithSuiteName:kSharedGroupIdentifier];
if (sharedPrefs == nil) {
NSLog(@"Error loading shared user defaults!");
}
A nil value indicates that the suite name is invalid.
Related Topics
Uisearchcontroller Persisting After Segue
Disabling Firebase Automatic Screen Reporting
How to Display the Emoji and Special Characters in Uilabel and Uitextviews
Uiscrollview Pauses Nstimer While Scrolling
How to Display Remote Document Using Qlpreviewcontroller in Swift
Applicationwillterminate: Not Being Called
Doing Undo and Redo with Cglayer Drawing
Build an iOS App Without Owning a MAC
Wkwebview Causes My View Controller to Leak
How to Crop Image Inside the Circle in Uiimageview in iOS
Failed to Load Optimized Model - Googlemaps Sdk iOS
How to Determine Which Textfield Is Active Swift
Receive Accelerometer Updates in Background Using Coremotion Framework
Play Audio from Internet Using Avaudioplayer
Limit Formatted Measurement to 2 Digits
iOS 9 Objective-C Screen Size Issues
Flutter: Cocoapods's Specs Repository Is Too Out-Of-Date to Satisfy Dependencies