I'm developing a universal iOS app that has some settings that make no sense for certain devices. Specifically, I'd like to hide certain settings from the user on devices where the portrait width is below a threshold. (So, for instance, some settings should not be available on an iPhone 7 but should be available on an iPhone 7 Plus.)
I'm aware that it's possible to have different settings for iPhone and iPad devices (as described in this thread), but that's not what I'm after. I'm also familiar with size-class-specific layouts, but that doesn't seem applicable to settings.
Is it possible to hide (or at least disable) certain settings based on the dimensions of the device on which the app is running?
Along the same lines, is it possible to have the default values for settings vary according to the display dimensions?
Sorry but it's impossible. You are right that all that you can is to have different settings.bundle for iPads and iPhones. Since iOS 4 Settings plists can be device-dependent: Root~ipad.plist will be used on iPad and Root~iphone.plist on iPhone. If not existed, Root.plist will be used.
So from my point of view you can achieve part of your goal using this 2 settings filed. For more specific cases you can set some default values when app launched. Settings.bundle can't be modified directly from code, so you can't remove or disable specific setting but you can change it value to some default value on specific device. Each item in Settings.bundle is paired with key in NSUserDefaults
so you can just set values in NSUserDefaults
and the settings application will automatically reflect this. It will be saved elsewhere, though. You can just read it back the same way as you would do with the settings bundle, also through NSUserDefaults
.
You can find code example in this answer https://stackoverflow.com/a/32648047/5285151
One more interesting option is to use https://github.com/futuretap/InAppSettingsKit which add same with native settings interface in to the app. And this internal settings synched with device settings but you have more control on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With