如果在另一个哈希中找到它们,我需要排除在我的应用程序的 Info.plist 中找到的特定键。目前我可以像这样访问 Info.plist 中的各个键
setting4Str = `/usr/libexec/PlistBuddy -c \"print :MySettingsDict:setting4" {settings_file}`
而且我可以在 plist 字典中的这个键处设置“setting 4 text”字符串...
但是,我希望能够遍历此 MysettingsDict 的所有键。有没有人有将 iOS XML plist 转换为 ruby 字典的方法?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>My App</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.company.appname</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>de</string>
<string>it</string>
<string>fr</string>
<string>ru</string>
<string>es</string>
</array>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.company.mySchemeName</string>
<key>CFBundleURLSchemes</key>
<array>
<string>mySchemeName</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.3.15.04170</string>
<key>Internal version</key>
<string>1.3.15.04170</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MysettingsDict</key>
<dict>
<key>setting1</key>
<false/>
<key>setting2</key>
<false/>
<key>setting3</key>
<false/>
<key>setting4</key>
<string>setting 4 text</string>
<key>setting5</key>
<string>setting 5 text</string>
<key>setting6</key>
<false/>
<key>setting7</key>
...
最佳答案
为那些想要解析 binary Info.plist 的人添加。
info_plist = File.read("Info.plist") # read binary plist
IO.popen('plutil -convert xml1 -r -o - -- -', 'r+') {|f|
f.write(info_plist)
f.close_write
info_plist = f.read # xml plist
}
现在 info_plist 是一个 xml 字符串。要快速提取一个属性,您可以使用正则表达式:
app_bundle = info_plist.scan(/<key>CFBundleIdentifier<\/key>\s+<string>(.+)<\/string>/).flatten.first
关于ios - 我可以将 iOS Info.plist 转换为 ruby 哈希吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31755612/