2012-07-30 75 views
0

捆綁PSMultiValueSpecifier標題和值我想通過我的應用程序來改變PSMultiValueSpecifier標題數組和值數組。這是我的Root.plist文件。我可以修改Root.plist在設置使應用程序

<?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>PreferenceSpecifiers</key> 
<array> 
    <dict> 
     <key>Type</key> 
     <string>PSGroupSpecifier</string> 
     <key>Title</key> 
     <string>Login Information</string> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSTextFieldSpecifier</string> 
     <key>Title</key> 
     <string>Restaurant Code</string> 
     <key>Key</key> 
     <string>Restaurant_Code_key</string> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSTextFieldSpecifier</string> 
     <key>Title</key> 
     <string>Password   </string> 
     <key>Key</key> 
     <string>Password_key</string> 
     <key>IsSecure</key> 
     <true/> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSToggleSwitchSpecifier</string> 
     <key>Title</key> 
     <string>Remember Login Information</string> 
     <key>Key</key> 
     <string>Remember_Login_Information_key</string> 
     <key>DefaultValue</key> 
     <false/> 
     <key>TrueValue</key> 
     <true/> 
     <key>FalseValue</key> 
     <false/> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSGroupSpecifier</string> 
     <key>Title</key> 
     <string>Menu Content</string> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSMultiValueSpecifier</string> 
     <key>Title</key> 
     <string>Default Language</string> 
     <key>Key</key> 
     <string>Default_Language_key</string> 
     <key>DefaultValue</key> 
     <integer>0</integer> 
     <key>Titles</key> 
     <array> 
      <string>English</string> 
      <string>Spanish</string> 
     </array> 
     <key>Values</key> 
     <array> 
      <integer>0</integer> 
      <integer>1</integer> 
     </array> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSToggleSwitchSpecifier</string> 
     <key>Title</key> 
     <string>Update Data on Launch</string> 
     <key>Key</key> 
     <string>Update_Data_key</string> 
     <key>DefaultValue</key> 
     <false/> 
     <key>TrueValue</key> 
     <true/> 
     <key>FalseValue</key> 
     <false/> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSGroupSpecifier</string> 
     <key>Title</key> 
     <string></string> 
    </dict> 
    <dict> 
     <key>Type</key> 
     <string>PSToggleSwitchSpecifier</string> 
     <key>Title</key> 
     <string>Reset on Next Launch</string> 
     <key>Key</key> 
     <string>Reset_key</string> 
     <key>DefaultValue</key> 
     <false/> 
     <key>TrueValue</key> 
     <true/> 
     <key>FalseValue</key> 
     <false/> 
    </dict> 

</array> 
<key>StringsTable</key> 
<string></string> 
</dict> 
</plist> 


I tried to change like this Through my application. 
<dict> 
<key>Type</key> 
<string>PSMultiValueSpecifier</string> 
<key>Title</key> 
<string>Default Language</string> 
<key>Key</key> 
<string>Default_Language_key</string> 
<key>DefaultValue</key> 
<integer>0</integer> 
<key>Titles</key> 
<array> 
<string>English</string> 
</array> 
<key>Values</key> 
<array> 
<integer>0</integer> 
</array> 
</dict> 

但是這不會改變標題和values.Please有人幫助我。下面給出的代碼,我使用。

NSURL * settingsURL = [[NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"Settings" withExtension:@"bundle"]] 
         URLForResource:@"Root" withExtension:@"plist"]; 
NSMutableDictionary * settingsDict = [NSMutableDictionary dictionaryWithContentsOfURL:settingsURL]; 
NSMutableArray *settingsArr = [settingsDict objectForKey:@"PreferenceSpecifiers"]; 

NSMutableDictionary *loTempDict = [[NSMutableDictionary alloc] init]; 
loTempDict = [settingsArr objectAtIndex:5]; 

NSArray *title_Array = [loTempDict objectForKey:@"Titles"]; 
NSArray *value_Array = [loTempDict objectForKey:@"Values"]; 

NSArray *lanArray_title = [NSArray arrayWithObject:@"French"]; 
NSArray *lanArray_value = [NSArray arrayWithObject:@"0"]; 

[loTempDict setObject:lanArray_title forKey:@"Titles"]; 
[loTempDict setObject:lanArray_value forKey:@"Values"]; 
[settingsArr replaceObjectAtIndex:5 withObject:loTempDict]; 


NSLog(@"final settingsArr ===%@ ",settingsArr); 

NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]; 

[settingsArr writeToFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"] atomically: TRUE]; 

感謝

回答

-1

這將解決你的問題

NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]; 

[settingsDict setValue:settingsArr forKey:@"PreferenceSpecifiers"]; 

[settingsDict writeToFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"] atomically: TRUE]; 
+1

號這不會幫助你無法寫入應用程序的主束。 -1。 – 2012-09-22 05:21:24

0

你不能做到這一點。出於安全原因,無法寫入應用程序包。你能想出最好的辦法是將文件複製到從應用程序包目錄到圖書館或文件目錄的修改 - 這些都是可寫,它們內部的文件可以被更新。

相關問題