Allows the custom executable action to be executed by Appfigurate. Any configuration properties you modify in the action method are persisted. Actions appear below properties in the Appfigurate UI.
Swift Objective-C Kotlin Java Dart JavaScript
Swift prototype
As you cannot annotate a Swift method with a property wrapper, your action methods must be specified manually.
Replace XXX
with the name of your action (e.g. freshInstall
)
Copy func XXXDescription () -> String
func XXXAction ()
func XXXRestart () -> Bool
If you return true
from your XXXRestart()
method, then the app will be restarted after the action method is executed.
Swift example
Copy @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
}
...
Objective-C prototype
Copy ACTION_METHOD(actionName, description, restart) { ... }
If restart
is YES
then the app will be restarted after the action method is executed.
Objective-C example
Copy @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];
}
...
Kotlin prototype
Copy @ActionMethod (description, restart)
If restart
is true
then the app will be restarted after the action method is executed.
Kotlin example
Copy @ActionMethod (description = "Resets application to fresh install state" , restart = false )
fun freshInstall () {
var preferences = context. getSharedPreferences ( "storage" , Context.MODE_PRIVATE)
var editor = preferences. edit ()
editor. clear ()
editor. apply ()
}
Java prototype
Copy @ ActionMethod (description , restart)
If restart
is true
then the app will be restarted after the action method is executed.
Java example
Copy @ ActionMethod (description = "Resets application to fresh install state" , restart = false )
public void freshInstall() {
SharedPreferences preferences = context . getSharedPreferences ( "storage" , MODE_PRIVATE);
SharedPreferences . Editor editor = preferences . edit ();
editor . clear ();
editor . apply ();
}
When an action is executed in the underlying native APLConfiguration
(iOS) or nz.co.electricbolt.appfiguratelibrary.Configuration
(Android) subclass, Flutter is also notified. Override the actionExecuted(action)
method in APLNativeConfiguration
as follows to receive the action:
Dart example
Copy import 'package:appfigurateflutter/appfigurateflutter.dart' ;
class ExampleConfiguration extends APLNativeConfiguration {
factory ExampleConfiguration () => _instance;
static final ExampleConfiguration _instance = ExampleConfiguration . _internal ();
ExampleConfiguration . _internal ();
@override
void actionExecuted ( String action) {
if (action == 'freshInstall' ) {
...
}
}
...
When an action is executed in the underlying native APLConfiguration
(iOS) or nz.co.electricbolt.appfiguratelibrary.Configuration
(Android) subclass, React Native is also notified. Subscribe to an event emitter to receive the action:
JavaScript example
Copy import {
NativeModules ,
NativeEventEmitter ,
} from 'react-native' ;
const { Appfigurate } = NativeModules;
const AppfigurateEvents = new NativeEventEmitter ( NativeModules .Appfigurate);
AppfigurateEvents .addListener ( 'APLConfigurationUpdated' , result => {
if ( result .APLConfigurationUpdatedAction == "freshInstall" ) {
...
}
});