有没有办法直接看到什么被保存到NSUserDefaults ?我想看看我的数据保存是否正确。
当前回答
Swift 5 Xcode 11.2解决方案
这是您的UserDefaults键值将在plist文件中的整个路径。跟踪并找到你的应用程序包标识符。plist文件。
/Users/'您的用户名'/Library/Developer/CoreSimulator/Devices/4176EED3-B9FC-4C77-A25E-ASD201B9FDFG2/data/Containers/ data/ Application/56D7CE31-9A8B-4371-9B0F-9604E239423B0/Library/Preferences
这里的“4176EED3-B9FC-4C77-A25E-ASD201B9FDFG2”是您的设备ID
“56D7CE31-9A8B-4371-9B0F-9604E239423B0”是您的申请ID
我通常通过在查找器中根据最近修改的日期对文件夹进行排序来获得它们。最近编辑的文件夹是我的设备ID和应用ID。
享受吧!
其他回答
在模拟器中运行时,我有时会使用下面的代码片段打印出NSUserDefaults文件的位置
NSArray *path = NSSearchPathForDirectoriesInDomains( NSLibraryDirectory, NSUserDomainMask, YES); NSString *folder = [path objectAtIndex:0]; NSLog(@"Your NSUserDefaults are stored in this folder: %@/Preferences", folder);
它生成首选项文件夹的路径
你的NSUserDefaults保存在这个文件夹:/Users/castle/Library/Application Support/iPhone Simulator/User/Applications/BC5056A0-F46B-4AF1-A6DC-3A7DAB984960/Library/Preferences
您的NSUserDefaults文件位于首选项文件夹中,并根据您的前缀和应用程序名称命名。
dk.castleandersen.dreamteam.grid.plist
我希望对于实际的设备也是如此。
模拟器应用程序
这个shell脚本搜索应用程序的名称,获取bundle id,并打开包含Plist文件的文件夹。
#!/bin/bash
appname="$1"
[ -z $appname ] && read -p "Application name : " appname
apppath=$(find ~/Library/Developer/CoreSimulator/Devices/ -name "$appname.app" -print -quit)
if [[ ! -z $apppath ]]; then
appbundle=$(osascript -e "id of app \"$apppath\"")
find ~/Library/Developer/CoreSimulator/Devices/ -name "$appbundle.plist" -exec bash -c 'open "$(dirname "$1")"' -- {} \;
else
echo "No application found by that name: $appname.app"
fi
扩展脚本版本
用法:iphone- App -文件夹“My App”
#!/bin/bash
appname="$1"
[ -z "$appname" ] && read -p "Application name : " appname
apppath=$(find ~/Library/Developer/CoreSimulator/Devices -name "$appname.app" -print -quit)
if [[ ! -z $apppath ]]; then
appbundle=$(osascript -e "id of app \"$apppath\"")
echo "Found app $appname (${appbundle})"
echo -e "\033[1;30m$apppath\033[0m"
plists=$(find ~/Library/Developer/CoreSimulator/Devices -name "$appbundle.plist" -print -quit)
count=$(echo plists | wc -l | sed "s/ //g")
if [[ $count -eq 1 ]] && [[ -f "$plists" ]]; then
echo -e "\033[1;32mUserDefaults found for $appname\033[0m"
echo -e "\033[1;30m$plists\033[0m"
plistutil -i "$plists"
/usr/bin/open $(dirname "$plists")
elif [[ ${#plists} -gt 0 ]]; then
echo -e "\033[1;32mUserDefaults found for $appname\033[0m"
i=1
while read line; do
echo "[${i}] ${line} "
i=$((i+1))
done < <(echo "$plists")
echo
read -p "Select defaults to read: [1-${count}] " choice
plist=$(echo ${plists} | sed -n "${choice}p")
plistutil -i "$plist"
/usr/bin/open $(dirname "$plist")
else
echo -e "\033[31mNo UserDefaults plist found for $appname\033[0m"
fi
else
echo -e "\033[31mNo application found by that name: $appname.app\033[0m"
fi
发现应用My app (com.organisation.MyApp) /用户/组织/图书馆/开发/ CoreSimulator /设备/ 3 e4c8dc3 - 6 - ff4 - 428 f - a624 b78dbe0b8c83 /数据/集装箱/包/应用程序/ 960 a5232 - 219 d - 4 - c46 - 8 - ca3 App.app - 01 e259d8ddad / 为我的应用程序找到UserDefaults
Mac应用程序
defaults read com.bundleid.app
MacOS应用 进入:/Users/{User}/Library/Containers/com。{你的公司}。{your app}/Data/Library/Preferences,然后用Xcode打开你的app的pList。
对于OS X应用程序,使用默认命令行实用程序更简单,而不是寻找应用程序的默认plist文件。
NAME defaults -- access the Mac OS X user defaults system SYNOPSIS defaults [-currentHost | -host hostname] read [domain [key]] defaults [-currentHost | -host hostname] read-type domain key defaults [-currentHost | -host hostname] write domain { 'plist' | key 'value' } defaults [-currentHost | -host hostname] rename domain old_key new_key defaults [-currentHost | -host hostname] delete [domain [key]] defaults [-currentHost | -host hostname] { domains | find word | help } DESCRIPTION defaults allows users to read, write, and delete Mac OS X user defaults from a command-line shell. Mac OS X applications and other programs use the defaults system to record user preferences and other information that must be maintained when the applications aren't running (such as default font for new documents, or the position of an Info panel). Much of this information is accessible through an appli- cation's Preferences panel, but some of it isn't, such as the position of the Info panel. You can access this information with defaults
例子:
$ defaults read com.apple.Safari
{
AutoplayPolicyWhitelistConfigurationUpdateDate = "2018-08-24 17:33:48 +0000";
AutoplayQuirksWhitelistConfigurationUpdateDate = "2018-08-24 17:33:48 +0000";
DefaultBrowserPromptingState2 = 4;
...
你可以在模拟器中找到你的应用的pList文件,如果你去:
/users/你的用户名/库/应用程序支持/iPhone模拟器/<Sim版本>/应用程序
这个目录有很多以GUID命名的目录。如果你正在开发一些应用程序,就会有一些这样的应用程序。所以你需要找到你的应用二进制:
find . -name foo.app
./1BAB4C83-8E7E-4671-AC36-6043F8A9BFA7/foo.app
然后进入GUID目录下的Library/Preferences目录。所以:
cd 1BAB4C83-8E7E-4671-AC35-6043F8A9BFA7/Library/Preferences
你应该会找到这样一个文件:
<Bundle Identifier>.foo.pList
在pList编辑器中打开它,并浏览您想要的持久值。
推荐文章
- Mac/OS X上的/var/lib/docker在哪里
- Xcode构建失败“架构x86_64未定义的符号”
- 如何使用Xcode创建。ipa文件?
- 动态改变UILabel的字体大小
- 在OSX 10.11中安装Scrapy时,“OSError: [Errno 1]操作不允许”(El Capitan)(系统完整性保护)
- registerForRemoteNotificationTypes: iOS 8.0及以上版本不支持
- 新的自动引用计数机制是如何工作的?
- 如何在Mac OS X 10.6中使硬件发出哔哔声
- 如何测试对象在Objective-C中的类?
- 在iPhone上确定用户是否启用了推送通知
- 是否有可能禁用浮动头在UITableView与UITableViewStylePlain?
- 从Cocoa应用程序执行一个终端命令
- Android Studio无法找到有效的Jvm(与MAC OS相关)
- 错误ITMS-9000:“冗余二进制文件上传。火车1.0版本已经有一个二进制版本上传。
- Swift -转换为绝对值