如何通过代码更改应用偏好设置?

如何通过代码更改应用偏好设置?

问题描述:

我已在设备设置应用中列出了我的应用。现在,我可以通过设备应用设置应用更改我的应用设置。
现在我想做的是相反的。
如果我在应用程序中更改了我的应用程序的首选项,我将尝试创建一个应用程序,以便它可以在设备设置应用程序中更改其首选项。

I have listed my app in the device setting app.Now I can change my app settings through the device app settings app. Now what I am trying to do is the reverse. I am trying to make a app so that it can itself change its preferences in the device settings app if I change the preferences of my app from within the app.

任何想法朋友,
谢谢所有。

Any ideas Friends, Thank You All.

很简单:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"MyPreferenceKey"];

NSUserDefaults 包括设置ints,浮动,字符串等。您还可以只使用-setValue:forKey:。

NSUserDefaults includes convenience methods for setting ints, floats, strings, and so on. You can also just use -setValue:forKey:.

当您使用 NSUserDefaults 更改应用程序中的值时,设置在设置应用程序中也会更改。

When you change a value in your app using NSUserDefaults, the setting well change in the Settings app, too.