NSUserDefault don't access value in a sandbox MacOS app

62 views Asked by At

I found after configuring my app sandbox, I can not access the preference value.

According the online blog, I have set com.apple.security.files.user-selected.read-write to YES in entitlements. Did I miss something?

Entitlements

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Once using sandbox mode, the value is nil.
NSString *value = [defaults objectForKey:@"MyPreference"];

ps: The preference key is correct, because when I close the sandbox, the preference value can be read normally.

1

There are 1 answers

0
Aura On

Thanks @Gerd K.

User defaults are stored in different locations for sandboxed and non-sandboxed apps.

In sandboxed app, the user default(.plist) is stored in /Users/USERNAME/Library/Containers/xiaofeihan.MyWebViewSample/Data/Library/Preferences

In non-sandboxed app, it is stored in Users/USERNAME/Library/Preferences