Skip to content

Subclassing APLConfiguration actions

Electric Bolt edited this page Jun 21, 2020 · 2 revisions

Documentation

HOME

UPGRADE 1.4.0 to 2.2.0
UPGRADE 2.1.1 to 2.2.0
UPGRADE 2.2.1 to 3.0.0

INTEGRATION

EXAMPLES
    AppfigurateExample
    ActionExample Extension
    WatchExample
    WatchExample Intent Extension

CONFIGURATION
    APLConfiguration subclass
        Custom executable actions
        Supported property types
            BOOL
            NSInteger
            float
            double
            plain NSString
            encrypted NSString
               Best practice
               String Encryption util
                  Troubleshooting
        UISlider icon types
        Overrides
    Advanced configuration
        App Startup
        Info.plist
        WCSession
    Additional functions
    Display overridden config

SECURITY
    Export compliance
    Best practice
    App Store compliance

TESTING
    Automation testing

Clone this wiki locally

Objective-C actions
Swift actions

Objective-C

ACTION_METHOD macro implements custom executable actions. Any configuration properties you modify in the action method are persisted. Actions appear below properties in Appfigurate.

Objective-C ACTION_METHOD implementation

ACTION_METHOD(actionName, description, restart) { ... }

Allows the custom executable action to be executed by Appfigurate. If restart is YES then the app will be restarted after the action method is executed.

Objective-C example

@implementation Configuration

ACTION_METHOD(freshInstall, "Resets application to fresh install state", NO) {
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSDictionary* dict = [defs dictionaryRepresentation];
    for (id key in dict) {
        [defs removeObjectForKey: key];
    }
    [defs synchronize];
}
...

Appfigurate UI element example

Swift

As you cannot annotate a Swift method with a property wrapper, your action methods must be specified manually. Any configuration properties you modify in the action method are persisted. Actions appear below properties in Appfigurate.

Swift implementation

Replace XXX with the name of your action (e.g. freshInstall)

func XXXDescription() -> String
func XXXAction()
func XXXRestart() -> Bool

Allows the custom executable action to be executed by Appfigurate. If you return true from your XXXRestart() method, then the app will be restarted after the action method is executed.

Swift example

@objcMembers class Configuration: APLConfiguration {

    func freshInstallDescription() -> String {
        return "Resets application to fresh install state"
    }
    
    func freshInstallAction() {
        let defs = UserDefaults.standard
        let dict = defs.dictionaryRepresentation()
        for key in dict.keys {
            defs.removeObject(forKey: key)
        }
        defs.synchronize()
    }

    func freshInstallRestart() -> Bool {
        return false
    }
    ...

Appfigurate UI element example