更新时间:2022-12-21 13:00:50
尝试一下:
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.de.iossoftware.SocialAppDataSharing"];
[userDefaults setValue:@55 forKey:@"myNumber"];
[userDefaults synchronize];
在iOS模拟器中执行一次,然后将其删除并添加:
Execute one time in iOS simulator and then remove it and add:
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.de.iossoftware.SocialAppDataSharing"];
NSLog(@"My number: %@",[userDefaults valueForKey:@"myNumber"]
再执行一次.您应该看到
And execute one more time. You should see the value saved before
NSError *error = nil;
NSLog(@"### Directory path: %@",[[NSFileManager defaultManager]contentsOfDirectoryAtPath:[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.de.iossoftware.SocialAppDataSharing"].path error:&error]);
NSLog(@"Error: %@",error);
在最后一行中,您将记录保存组文件的文件路径.在查找器中打开它,您应该在...../Library/Preferences/下创建一个包含创建的NSUserdefaults的plist.
And in the last line you will log the file path where the group files are saved. Open it in the finder and you should see under ...../Library/Preferences/ a plist containing the NSUserdefaults created