Reputation: 3354
MDM Providers write to a dictionary which is retrievable using
NSUserDefaults.StandardUserDefaults.DictionaryForKey("com.apple.configuration.managed")
How can I programatically write key/value pairs to this dictionary?
Upvotes: 0
Views: 278
Reputation: 6641
Firstly retrieve the configuration dictionary:
NSMutableDictionary configDic = NSUserDefaults.StandardUserDefaults.DictionaryForKey("com.apple.configuration.managed").MutableCopy() as NSMutableDictionary;
Then you can modify this NSMutableDictionary
like:
configDic["key1"] = (NSString)"value1";
At last write back to NSUserDefaults
:
NSUserDefaults.StandardUserDefaults.SetValueForKey(configDic, (NSString)"com.apple.configuration.managed");
NSUserDefaults.StandardUserDefaults.Synchronize();
Because NSDictionary
can't be modified after initialization, we need to convert it to NSMutableDictionary
. If the value of configDic
is type of NSDictionary
(or NSArray
), we also need to copy it deeply before we want to modify it.
Upvotes: 1