在做iOS Extension时,当你试图向APP Group写入数据,调试时可能会报以下错误:
[User Defaults] Failed to read values in CFPrefsPlistSource<0x1700f8380> (Domain: group.com.company.App, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null)): Using kCFPreferencesAnyUser with a container is only allowed for System Containers
出现这个错误,很可能是因为疏忽写下了以下代码:
[[NSUserDefaults standardUserDefaults] initWithSuiteName:@"group.xxx.com"];
因为这个方法重置了你的默认的沙盒。而APP Group的沙盒获取方法为:
[[NSUserDefaults alloc] initWithSuiteName:@"group.xxx.com"];
正是因为standardUserDefaults与alloc的差异导致了上述错误
网友评论