5

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?

Community
  • 1
  • 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Well how about having the settings in a custom model, stored within an array and just initialize the array with the appropriate settings for the device? What exactly are you looking for ? – Lefteris Jan 30 '17 at 11:24
  • @Lefteris - That's not how settings work in iOS. The settings options are defined in a `Settings.bundle` file that is read by the device's Settings app. The settings might be displayed before the app has even run once. Even if the app were guaranteed to run first, I haven't found an API that allows the app to programmatically affect what settings are displayed to the user. – Ted Hopp Jan 30 '17 at 16:13
  • I didn't understand you meant the system settings. AFAIK you can't do what you want. [I would suggest to look here](http://stackoverflow.com/a/1211627/312312) for an alternative – Lefteris Jan 30 '17 at 16:58
  • @Lefteris - It's a shame if there's no way to do this. (It's simple enough on Android.) I guess I'll be looking into managing my settings strictly in-app, using one of the alternatives you so kindly pointed out. Too bad it means that there'd then be no way to access my app's settings through the system settings app. – Ted Hopp Feb 02 '17 at 15:49

1 Answers1

2

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.

Community
  • 1
  • 1
oroom
  • 1,318
  • 11
  • 10
  • InAppSettingsKit seems very promising, so +1 for that. The suggestion to set default values in code, however, does not do what I am looking for: that when running on small devices, the user not even see settings that only make sense for larger devices. (In my particular app, this requirement splits the iPhone population in two, rather than dividing iPhones from iPads.) Also, since the user can run the system's Settings app before my app ever runs, this trick is far from foolproof. It's all very frustrating; Android does a much better job of dealing with device fragmentation. – Ted Hopp Feb 05 '17 at 16:15