InAppSettingsKit Documentation

repository·master·Indexed 25 days ago

https://github.com/futuretap/inappsettingskit

A 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.

Tokens
4.2K
Snippets
5
Records
23
Agent score
35%

What's inside InAppSettingsKit

  1. Register Default Values from Plist

    master

    To ensure NSUserDefaults contains the DefaultValue defined in your Settings Plist (so they are available at app launch), use IASKSettingsReader to generate a registration dictionary. This prevents desync between your Plist and NSUserDefaults.

    NSDictionary *defaultDict = [appSettingsViewController.settingsReader gatherDefaultsLimitedToEditableFields:YES];
    [NSUserDefaults.standardUserDefaults registerDefaults:defaultDict];
  2. Configure InAppSettingsKit via Storyboard

    master

    To set up the settings view using Storyboards:

    1. Drag a Table View Controller embedded in a Navigation Controller into your storyboard.
    2. Set the Table View Controller class to IASKAppSettingsViewController.
    3. Set the Table View style to Grouped.
    4. If presenting modally, set "Show Done Button" to "On" under "App Settings View Controller".
    5. Set the delegate to conform to IASKAppSettingsViewControllerDelegate and implement -settingsViewControllerDidEnd: to dismiss the view controller.
  3. Manage variable items with IASKListGroupSpecifier

    master

    IASKListGroupSpecifier manages a variable number of items (e.g., accounts, tags) based on the content in NSUserDefaults or your custom settings store.

    Key Features:

    • Dynamic Content: The number of ItemSpecifier cells is determined by your data store.
    • Deletion: If the Deletable parameter is set to YES, 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:

  4. Integrate InAppSettingsKit into your app

    master

    To use InAppSettingsKit, first add a Settings.bundle to your project and configure your settings in Root.plist.

    To display the settings interface, instantiate IASKAppSettingsViewController and 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];
  5. Use InAppSettingsKit in a Swift Package

    master

    If you are using InAppSettingsKit within a modularized Swift Package, you must include the InAppSettings.bundle as a resource and explicitly set the bundle property of the IASKAppSettingsViewController to Bundle.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) { }
    }
  6. Configure IASKDatePickerSpecifier

    master

    Use IASKDatePickerSpecifier to display a UIDatePicker.

    Configuration Options:

    • DatePickerMode: Date, Time, or DateAndTime (Default: DateAndTime).
    • DatePickerStyle: Compact, Wheels, or Inline (Default: Wheels). Requires iOS 14+; otherwise falls back to Wheels.
    • 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.
  7. Configure the Web View Controller

    master

    Use IASKAppSettingsWebViewController to display a fullscreen WKWebView inside 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: PSChildPaneSpecifier
    • IASKViewControllerClass: IASKAppSettingsWebViewController
    • IASKViewControllerSelector: 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 to YES to extend content below the navigation bar.
    • IASKWebViewShowProgress: Set to YES to show a dynamic progress bar below the navigation bar instead of the default activity indicator.
    • IASKWebViewShowNavigationalButtons: Set to YES to show back/forward buttons in the navigation bar.
    • IASKWebViewHideBottomBar: Set to YES to hide the tab bar when pushed onto a navigation controller (ignored if presented modally).
  8. Customize Specifier Appearance (Subtitles, Alignment, Font, and Icons)

    master

    You can enhance the visual presentation of various specifiers using the following keys in your Plist:

    Subtitles

    Use IASKSubtitle for Toggle, ChildPane, OpenURL, MailCompose, and Button.

    • Subtitles are left-aligned.
    • Supports localizable Strings or a Dictionary. For boolean toggles, use YES and NO as keys. A __default__ key can be used for unmatched values.

    Text Alignment

    Override default alignment using IASKTextAlignment with 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 IASKAdjustsFontSizeToFitWidth with a value of NO.

    Icons

    Add an image using IASKCellImage.

    • The suffix .png or @2x.png is automatically appended.
    • For Buttons and ChildPanes, you can provide a highlight image by adding the Highlighted.png or Highlighted@2x.png suffix.
    • If the resource is missing, the kit falls back to SF Symbols.
  9. Handle Setting Changes and Dynamic Hiding

    master

    Listen for Changes

    Observe IASKSettingChangedNotification to react to setting updates. The userInfo dictionary 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 hiddenKeys property or the following method:

    [IASKAppSettingsViewController setHiddenKeys:(NSSet*)hiddenKeys animated:(BOOL)animated];

    Including a PSGroupSpecifier key in the hiddenKeys set will hide the entire section.