/ManagedAppConfigLib

Makes Managed AppConfig on iOS, tvOS, and macOS easier to work with.

Primary LanguageSwiftMIT LicenseMIT

ManagedAppConfigLib

Overview

The purpose of ManagedAppConfigLib is to make it much easier to work with Apple's Managed App Configuration by providing a class that manages access to it, as well as some property wrappers for modern Swift usage.

Managed App Configuration is supported by Apple on iOS 7+, macOS 11+, and tvOS 10.2+.

Installation

CocoaPods

Install via Cocoapods by adding the following to your Podfile under your desired targets:

pod 'ManagedAppConfigLib'

Swift Package Manager

Install with Swift Package Manager by adding the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/jamf/ManagedAppConfigLib")
],

Learn More

The documentation for this package was generated by DocC using publish_docs.yml with GitHub Actions.

Basic Usage

You will need to import ManagedAppConfigLib in each Swift file you wish to use it.

SwiftUI Property Wrapper

Functions much like the @AppStorage property wrapper built in to SwiftUI. Provides a type-safe read-only property that keeps itself current with any changes in the AppConfig value, and causes a SwiftUI redraw when it's value changes.

// If AppConfig "title" doesn't exist or is not a string, will have the value "Default title".
@AppConfig("title") var title = "Default title"
// If AppConfig "featureEnabled" doesn't exist or is not a boolean, will have the value `false`.
@AppConfig("featureEnabled") var isEnabled: Bool = false
// If AppConfig "orgColor" doesn't exist or is not a string, this will be nil.
@AppConfig("orgColor") var organizationHexColor: String?

Non-SwiftUI Property Wrapper

Functions much like the @AppConfig property wrapper except that it does not require SwiftUI. Provides a read-only property that keeps itself current with any changes in the AppConfig value. This is useful for UIKit or AppKit code or simple Foundation code in models or cli tools.

@AppConfigPlain("title") var title = "Default title"
@AppConfigPlain("featureEnabled") var isEnabled: Bool = false
@AppConfigPlain("orgColor") var organizationHexColor: String?

Simple functional use

  • Retrieve a Managed App Configuration value
if let deviceId = ManagedAppConfig.shared.getConfigValue(forKey: "deviceId") as? String {
    print(deviceId)
}
  • Register a closure to be executed when Managed App Configuration changes
let myClosure = { (configDict: [String: Any?]) -> Void in
    print("Managed App Configuration changed")
}
ManagedAppConfig.shared.addAppConfigChangedHook(myClosure)
  • Place a value into Managed App Feedback
let numberOfErrors = 0
ManagedAppConfig.shared.updateValue(numberOfErrors, forKey: "errorCount")

Contributing

This repository now requires verified signed commits. You can find out more about signing commits on GitHub Docs.