jamesmontemagno / Xamarin.Plugins

Cross-platform Native API Access from Shared Code!
MIT License
1.3k stars 380 forks source link

Settings - Possibility of using alternative NSUserDefaults in iOS #309

Closed papafe closed 8 years ago

papafe commented 8 years ago

Please take a moment to fill out the following (change to preview to check or place x in []):

This is a

Which plugin does this impact:

Version Number of Plugin: 2.1.0 Device Tested On: iPhone 6.0

Expected Behavior

The settings plugin uses the NSUserDefaults.StandardUserDefaults as default, not allowing to define any other NSUserDefaults database to store the objects. This is useful, for example, in the case in which an app group is used, and it is necessary to have shared settings between the container app and the extensions / other apps in the group.

jamesmontemagno commented 8 years ago

Do you have an idea of what the implementation would be? Should it be for all settings or only specific settings. Is there something similar on Android/Windows that could be abstracted?

papafe commented 8 years ago

There is one line that is responsible of this behaviour:

var defaults = NSUserDefaults.StandardUserDefaults;

You can find it here.

The code should be modified in such a way that the defaults variable can be instantiated to whatever NSUserDefaults the user needs. For instance it could be instantiated to new NSUserDefaults("groupID", NSUserDefaultsType.SuiteName) in case one needs to use an app group.

Regarding if it should be only for specific settings, I think it is not strictly necessary. Having the possibility to have shared settings in an app group would be already a step forward, while having different user defaults for different settings could be too much.

And, as far as I know, there is no equivalent in Android or Windows.

neelamc23 commented 8 years ago

I think an Android equivalent would be SharedPreferences.

jamesmontemagno commented 8 years ago

For Android I store in SharedPreferences, which means you could build a preference screen via xml.

heathhodgert commented 8 years ago

This would be a very nice feature. I already use your settings plugin but had to spin my own for app group settings. The only thing i see in windows is Extension folders and managing our own settings file.

jamesmontemagno commented 8 years ago

This issue was moved to jamesmontemagno/SettingsPlugin#3