-
-
Save xslim/1781373 to your computer and use it in GitHub Desktop.
Scripts to play with Settings.bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# addDebugSettingsChild.sh | |
# | |
# Simple script to inject a Debug menu in an iPhone Settings plist. | |
# | |
# created 10.15.2008 by Andy Mroczkowski, mrox.net | |
THIS="`basename $0`" | |
PLISTBUDDY="/usr/libexec/PlistBuddy -x" | |
set -e | |
if [ -z "$1" ]; then | |
echo "Usage:" | |
echo " $THIS plist_file [child_pane_name]" | |
echo " - If unspecified, child_pane_name is 'Debug'" | |
exit 1 | |
fi | |
if [ ! -e "$1" ]; then | |
echo "[$THIS] file not found: '$1'" | |
exit 2 | |
fi | |
if [ ! -z "$2" ]; then | |
CHILD_PANE_NAME="$2" | |
else | |
CHILD_PANE_NAME="Debug" | |
fi | |
TARGET="$1" | |
echo "[$THIS] adding '$CHILD_PANE_NAME' child to: $TARGET" | |
$PLISTBUDDY -c "Add PreferenceSpecifiers:0 dict" "$TARGET" | |
$PLISTBUDDY -c "Add PreferenceSpecifiers:0:Type string 'PSGroupSpecifier'" "$TARGET" | |
$PLISTBUDDY -c "Add PreferenceSpecifiers:1 dict" "$TARGET" | |
$PLISTBUDDY -c "Add PreferenceSpecifiers:1:Type string 'PSChildPaneSpecifier'" "$TARGET" | |
$PLISTBUDDY -c "Add PreferenceSpecifiers:1:Title string '$CHILD_PANE_NAME Settings'" "$TARGET" | |
$PLISTBUDDY -c "Add PreferenceSpecifiers:1:File string '$CHILD_PANE_NAME'" "$TARGET" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configuration = ENV["CONFIGURATION"] | |
project_dir = ENV["PROJECT_DIR"] | |
settings_bundle = "#{project_dir}/Resources/Settings.bundle" | |
plist_location = "#{project_dir}/Resources/SettingPlists" | |
release_or_debug = ENV["CONFIGURATION"] == "Debug" ? "Debug" : "Release" | |
settings_plist = "#{plist_location}/SettingsRoot#{release_or_debug}.plist" | |
system("cp #{settings_plist} #{settings_bundle}/Root.plist"); | |
system("touch #{settings_bundle}/Root.plist"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ "$CONFIGURATION" = "Release" ] ; then | |
echo "Replacing $CODESIGNING_FOLDER_PATH/Settings.bundle for 'Release' build" | |
APPVERSION="`/usr/libexec/PlistBuddy -c \"Print :CFBundleVersion\" \"$CODESIGNING_FOLDER_PATH/Info.plist\"`" | |
SETTINGSBUNDLEPATH="$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist" | |
/usr/libexec/PlistBuddy -c "Delete :PreferenceSpecifiers" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :StringsTable string 'Root'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers array" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0 dict" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0:Type string 'PSGroupSpecifier'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0:Title string 'Version Information'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Type string 'PSTitleValueSpecifier'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Title string 'Release:'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Key string 'appVersion'" "$SETTINGSBUNDLEPATH" | |
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:DefaultValue string '$APPVERSION'" "$SETTINGSBUNDLEPATH" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setSettingsBundleDefaults | |
if (nil == [[NSUserDefaults standardUserDefaults] valueForKey:@"xyz"]) | |
[MyAppDelegate setSettingsBundleDefaults]; | |
+ (void)setSettingsBundleDefaults | |
{ | |
[MyAppDelegate setSettingsBundleDefaultsForFile:@"Root.plist"]; | |
} | |
+ (void)setSettingsBundleDefaultsForFile:(NSString *)plistFileName | |
{ | |
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; | |
//bundle path | |
NSString *bPath = [[NSBundle mainBundle] bundlePath]; | |
NSString *settingsPath = [bPath stringByAppendingPathComponent:@"Settings.bundle"]; | |
NSString *plistFile = [settingsPath stringByAppendingPathComponent:plistFileName]; | |
//preferences | |
NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:plistFile]; | |
NSArray *preferencesArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"]; | |
//loop thru prefs | |
NSDictionary *item; | |
for(item in preferencesArray) | |
{ | |
//get the key | |
NSString *keyValue = [item objectForKey:@"Key"]; | |
//get the default | |
id defaultValue = [item objectForKey:@"DefaultValue"]; | |
// if we have both, set in defaults | |
if (keyValue && defaultValue) | |
[standardUserDefaults setObject:defaultValue forKey:keyValue]; | |
//get the file item if any - (recurse thru the other settings files) | |
NSString *fileValue = [item objectForKey:@"File"]; | |
if (fileValue) | |
[MyAppDelegate setSettingsBundleDefaultsForFile:[fileValue stringByAppendingString:@".plist"]]; | |
} | |
[standardUserDefaults synchronize]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://mrox.net/blog/2008/11/16/adding-debug-only-preferences-in-iphone-applications/