InAppSettingsKit Documentation
repository·master·Indexed 25 days ago
https://github.com/futuretap/inappsettingskitA framework for iOS, Catalyst, and visionOS developers to present an in-app settings interface that replicates and extends the system's Settings.app using a Settings.bundle. It supports custom specifiers for URLs, mail composition, date pickers, and custom views, as well as integration via Swift Package Manager, CocoaPods, and Carthage.
What's inside InAppSettingsKit
- InAppSettingsKit is designed to aggregate common or universal Xcode configuration settings. It organizes these settings into hierarchical Xcode configuration files to allow for easy modification and reuse across different projects or targets.
Register Default Values from Plist
masterTo ensure
NSUserDefaultscontains theDefaultValuedefined in your Settings Plist (so they are available at app launch), useIASKSettingsReaderto generate a registration dictionary. This prevents desync between your Plist andNSUserDefaults.NSDictionary *defaultDict = [appSettingsViewController.settingsReader gatherDefaultsLimitedToEditableFields:YES]; [NSUserDefaults.standardUserDefaults registerDefaults:defaultDict];Configure InAppSettingsKit via Storyboard
masterTo set up the settings view using Storyboards:
- Drag a Table View Controller embedded in a Navigation Controller into your storyboard.
- Set the Table View Controller class to
IASKAppSettingsViewController. - Set the Table View style to
Grouped. - If presenting modally, set "Show Done Button" to "On" under "App Settings View Controller".
- Set the delegate to conform to
IASKAppSettingsViewControllerDelegateand implement-settingsViewControllerDidEnd:to dismiss the view controller.
Manage variable items with IASKListGroupSpecifier
masterIASKListGroupSpecifiermanages a variable number of items (e.g., accounts, tags) based on the content inNSUserDefaultsor your custom settings store.Key Features:
- Dynamic Content: The number of
ItemSpecifiercells is determined by your data store. - Deletion: If the
Deletableparameter is set toYES, cells can be deleted via swipe. - AddSpecifier: Controls the last item in the group. It can be a text field, toggle, slider, or a child pane (presented modally with Cancel/Done buttons).
Validation: To enable/disable the 'Done' button in a modal child pane, implement:
- (BOOL)settingsViewController:childPaneIsValidForSpecifier:contentDictionary:- Dynamic Content: The number of
Install InAppSettingsKit
masterYou can install InAppSettingsKit using Swift Package Manager, CocoaPods, or Carthage.Integrate InAppSettingsKit into your app
masterTo use InAppSettingsKit, first add a
Settings.bundleto your project and configure your settings inRoot.plist.To display the settings interface, instantiate
IASKAppSettingsViewControllerand push it onto a navigation stack or present it modally.// Swift let appSettingsViewController = IASKAppSettingsViewController() navigationController.pushViewController(appSettingsViewController, animated: true)// Objective-C IASKAppSettingsViewController *appSettingsViewController = [[IASKAppSettingsViewController alloc] init]; [self.navigationController pushViewController:appSettingsViewController animated:YES];Use InAppSettingsKit in a Swift Package
masterIf you are using InAppSettingsKit within a modularized Swift Package, you must include the
InAppSettings.bundleas a resource and explicitly set thebundleproperty of theIASKAppSettingsViewControllertoBundle.module.// Package.swift configuration let package = Package( name: "SettingsPackage", platforms: [.iOS(.v17)], dependencies: [ .package(url: "https://github.com/futuretap/inappsettingskit", from: "3.4.0") ], .target( name: "SettingsPackage", dependencies: [ .product(name: "InAppSettingsKit", package: "inappsettingskit"), ], resources: [ .copy("InAppSettings.bundle") ] ) ) // Implementation in SwiftUI/UIKit struct InAppSettingsView: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> some UIViewController { let iask = IASKAppSettingsViewController(style: .insetGrouped) iask.bundle = Bundle.module // IMPORTANT return iask } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { } }Configure IASKDatePickerSpecifier
masterUse
IASKDatePickerSpecifierto display aUIDatePicker.Configuration Options:
DatePickerMode:Date,Time, orDateAndTime(Default:DateAndTime).DatePickerStyle:Compact,Wheels, orInline(Default:Wheels). Requires iOS 14+; otherwise falls back toWheels.MinuteInterval: The interval for minutes (Default:1).
Customization via Delegate:
-(NSDate*)settingsViewController:(IASKAppSettingsViewController*)sender dateForSpecifier:(IASKSpecifier*)specifier;: Use this if you store dates in a custom format. Called when the user selects the title cell.-(NSString*)settingsViewController:(IASKAppSettingsViewController*)sender datePickerTitleForSpecifier:(IASKSpecifier*)specifier;: Customize the displayed value in the title cell.-(void)settingsViewController:(IASKAppSettingsViewController*)sender setDate:(NSDate*)date forSpecifier:(IASKSpecifier*)specifier;: Called when the user changes the date/time value.
Customize Toggle Styles
masterBy default,PSToggleSwitchSpecifieruses aUISwitch. To display checkmarks for selected keys instead, set theIASKToggleStyleoption toCheckmark.Configure the Web View Controller
masterUse
IASKAppSettingsWebViewControllerto display a fullscreenWKWebViewinside your application. This keeps the URL private as it does not reveal the URL to the user or allow opening in external browsers like Safari.In your Settings plist, use the following mandatory properties:
Type:PSChildPaneSpecifierIASKViewControllerClass:IASKAppSettingsWebViewControllerIASKViewControllerSelector:initWithFile:specifier:Title: The localized title of the row.File: The URL to load (e.g.,https://www.futuretap.com).
Optional customization properties:
IASKWebViewFullscreen: Set toYESto extend content below the navigation bar.IASKWebViewShowProgress: Set toYESto show a dynamic progress bar below the navigation bar instead of the default activity indicator.IASKWebViewShowNavigationalButtons: Set toYESto show back/forward buttons in the navigation bar.IASKWebViewHideBottomBar: Set toYESto hide the tab bar when pushed onto a navigation controller (ignored if presented modally).
Customize Specifier Appearance (Subtitles, Alignment, Font, and Icons)
masterYou can enhance the visual presentation of various specifiers using the following keys in your Plist:
Subtitles
Use
IASKSubtitleforToggle,ChildPane,OpenURL,MailCompose, andButton.- Subtitles are left-aligned.
- Supports localizable Strings or a Dictionary. For boolean toggles, use
YESandNOas keys. A__default__key can be used for unmatched values.
Text Alignment
Override default alignment using
IASKTextAlignmentwith these values:IASKUITextAlignmentLeft(ChildPane, TextField, Buttons, OpenURL, MailCompose)IASKUITextAlignmentCenter(ChildPane, Buttons, OpenURL)IASKUITextAlignmentRight(ChildPane, TextField, Buttons, OpenURL, MailCompose)
Font Size
To prevent labels from automatically shrinking to fit, add
IASKAdjustsFontSizeToFitWidthwith a value ofNO.Icons
Add an image using
IASKCellImage.- The suffix
.pngor@2x.pngis automatically appended. - For Buttons and ChildPanes, you can provide a highlight image by adding the
Highlighted.pngorHighlighted@2x.pngsuffix. - If the resource is missing, the kit falls back to SF Symbols.
Handle Setting Changes and Dynamic Hiding
masterListen for Changes
Observe
IASKSettingChangedNotificationto react to setting updates. TheuserInfodictionary contains the affected key and its new value.Hide/Show Cells Dynamically
To hide specific cells or entire sections based on other settings, use the
hiddenKeysproperty or the following method:[IASKAppSettingsViewController setHiddenKeys:(NSSet*)hiddenKeys animated:(BOOL)animated];Including a
PSGroupSpecifierkey in thehiddenKeysset will hide the entire section.