Functions
The following functions are available globally.
-
Availability: iOS apps only.
You must call
APLApplicationDidFinishLaunchingWithOptions
in your app delegate’sapplication:didFinishLaunchingWithOptions:
method.Objective-C example
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { APLApplicationDidFinishLaunchingWithOptions(launchOptions); return YES; }
Swift example
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { APLApplicationDidFinishLaunchingWithOptions(launchOptions) return true }
Declaration
Objective-C
extern void APLApplicationDidFinishLaunchingWithOptions( NSDictionary *_Nullable launchOptions)
Swift
func APLApplicationDidFinishLaunchingWithOptions(_ launchOptions: [AnyHashable : Any]?)
-
Availability: iOS apps only.
You must call
APLApplicationOpenURL
in your app delegate’sapplication:openURL:options:
method.Objective-C example
- (BOOL) application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { return APLApplicationOpenURL(url); }
Swift example
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return APLApplicationOpenURL(url) }
Declaration
Objective-C
extern BOOL APLApplicationOpenURL(NSURL *_Nonnull url)
Swift
func APLApplicationOpenURL(_ url: URL) -> Bool
-
Availability: watchOS extensions only.
You must call
APLApplicationDidFinishLaunching
in your extension’s delegateapplicationDidFinishLaunching
method.Objective-C example
- (void) applicationDidFinishLaunching { APLApplicationDidFinishLaunching(); }
Swift example
func applicationDidFinishLaunching() { APLApplicationDidFinishLaunching() }
Declaration
Objective-C
extern void APLApplicationDidFinishLaunching(void)
Swift
func APLApplicationDidFinishLaunching()
-
Availability: watchOS extensions only.
Receives configuration commands and payloads from the paired iPhone’s Appfigurate app.
If your watch app has its own
WCSessionDelegate
, then call theAPLSessionDidReceiveMessage()
function from within yoursession:didReceiveMessage:replyHandler:
method (see examples below). If your watch app does not have its ownWCSessionDelegate
then you do not need to do anything - Appfigurate library installs aWCSessionDelegate
and callsAPLSessionDidReceiveMessage()
automatically.Objective-C example
- (void) session: (WCSession*) session didReceiveMessage: (NSDictionary<NSString*,id>*) message replyHandler: (void (^)(NSDictionary<NSString*,id>*)) replyHandler { NSDictionary* reply = APLSessionDidReceiveMessage(message); if (reply != nil) replyHandler(reply); else ...
Swift example
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) { let reply = APLSessionDidReceiveMessage(message) if reply != nil { replyHandler(reply) } else { ...
Declaration
Objective-C
extern NSDictionary *_Nullable APLSessionDidReceiveMessage( NSDictionary<NSString *, id> *_Nonnull message)
Swift
func APLSessionDidReceiveMessage(_ message: [String : Any]) -> [AnyHashable : Any]?
-
Availability: All.
Returns the version of the Appfigurate library in the format “major.minor.patch”. e.g. “5.1.2”
Declaration
Objective-C
extern NSString *_Nonnull APLVersion(void)
Swift
func APLVersion() -> String
-
Availability: All.
Registers a delegate method that will be called back when Appfigurate has updated the configuration of the app or extension. See also
APLAddConfigurationUpdatedBlock
function for block based callback.Declaration
Objective-C
extern void APLAddConfigurationUpdatedListener(id<APLConfigurationUpdated> _Nonnull target)
Swift
func APLAddConfigurationUpdatedListener(_ target: any APLConfigurationUpdated)
-
Availability: All.
Registers a block that will be called back when Appfigurate has updated the configuration of the app or extension. Returns an opaque object to act as the observer. See also
APLRemoveConfigurationUpdatedBlock
.Declaration
Objective-C
extern id<NSObject> _Nonnull APLAddConfigurationUpdatedBlock( APLConfigurationUpdatedBlock _Nonnull block)
Swift
func APLAddConfigurationUpdatedBlock(_ block: @escaping APLConfigurationUpdatedBlock) -> any NSObjectProtocol
-
Availability: All.
Unregisters the delegate method that will be called back when Appfigurate has updated the configuration of the application. You may optionally call this method before the target is deallocated.
Declaration
Objective-C
extern void APLRemoveConfigurationUpdatedListener( id<APLConfigurationUpdated> _Nonnull target)
Swift
func APLRemoveConfigurationUpdatedListener(_ target: any APLConfigurationUpdated)
-
Availability: All.
Unregisters the block that will be called back when Appfigurate has updated the configuration of the application. You must call this method before the block is deallocated. The observer argument is the result of
APLAddConfigurationUpdatedBlock
.Declaration
Objective-C
extern void APLRemoveConfigurationUpdatedBlock(id<NSObject> _Nonnull observer)
Swift
func APLRemoveConfigurationUpdatedBlock(_ observer: any NSObjectProtocol)
-
Availability: All.
Saves the configuration persisted in the keychain into temporary storage. Some apps have functionality to erase the keychain to reset apps back to “factory defaults”, which has the side effect of removing any Appfigurate configuration persisted in the keychain. Usage example:
Objective-C example
- (void) eraseKeychain { APLSaveConfiguration(); NSArray* secItemClasses = @[(__bridge id) kSecClassGenericPassword, (__bridge id) kSecClassInternetPassword, (__bridge id) kSecClassCertificate, (__bridge id) kSecClassKey, (__bridge id) kSecClassIdentity]; for (id secItemClass in secItemClasses) { NSDictionary *spec = @{(__bridge id)kSecClass: secItemClass}; SecItemDelete((__bridge CFDictionaryRef)spec); } APLRestoreConfiguration(); }
Declaration
Objective-C
extern void APLSaveConfiguration(void)
Swift
func APLSaveConfiguration()
-
Availability: All.
Restores the configuration from temporary storage back into the keychain. See also
APLSaveConfiguration
for more details and usage example.Declaration
Objective-C
extern void APLRestoreConfiguration(void)
Swift
func APLRestoreConfiguration()
-
Availability: All.
The application or framework that links the static AppfigurateLibrary.xcframework must define a function with the following prototype that returns the
Class
(Objective-C) orAnyClass
(Swift) of yourAPLConfiguration
subclass.Objective-C example
- (Class) _Nonnull APLConfigurationClass(void) { return [ExampleConfiguration class]; }
Swift example
@_cdecl("APLConfigurationClass") func APLConfigurationClass() -> AnyClass { return ExampleConfiguration.self }
Declaration
Objective-C
extern Class _Nonnull APLConfigurationClass(void)
Swift
func APLConfigurationClass() -> AnyClass
-
Availability: iOS XCUITest automation testing only.
Sends a message to the application under test, and waits for a response. You can only call this function from within an XCUITest automation test case.
name
is the message name, must not benil
or blank, maximum 255 bytes after encoding with UTF-8.plist
is a property list object ornil
.timeout
is the duration in seconds you expect to receive a response, otherwise anAppfigurateLibraryException
is thrown (minimum of 3.0 seconds). Returns a property list object ornil
from the application under test. See alsoAPLAutomationMessageReceivedBlock
.Objective-C example
- (void) testLogin { XCUIApplication *app = [XCUIApplication new]; [app launch]; APLAutomationSendMessage(@"SetResponseData", @{ @"Request": @"/login", @"Status": [NSNumber numberWithInt: 200], @"Response": @"{'Customer':'2311569'}" }, 3.0); ...
Swift example
func testLogin() { var app = XCUIApplication() app.launch APLAutomationSendMessage("SetResponseData", [ "Request": "/login", "Status": 200, "Response": "{'Customer':'2311569'}" ], 3.0) ...
Declaration
Objective-C
extern id _Nullable APLAutomationSendMessage(NSString *_Nonnull name, id _Nullable plist, NSTimeInterval timeout)
Swift
func APLAutomationSendMessage(_ name: String, _ plist: Any?, _ timeout: TimeInterval) -> Any?
-
Availability: iOS XCUITest automation testing only.
Register a single block (in the application under test) that will be invoked when an XCUITest automation test case has sent a message using the
APLAutomationSendMessage
function. The-[APLConfiguration allowInvalidSignatures]
method in the application under test must returnYES
for the message to be processed. See alsoAPLAutomationSendMessage
.Objective-C example
APLAutomationMessageReceivedBlock(^NSObject* (NSString* name, id data) { if ([name isEqualToString: @"SetResponseData"]) { [MockedHttpInterceptor setResponse: data]; } return nil; });
Swift example
APLAutomationMessageReceivedBlock { (name: String, data: Any) -> NSObject in if name == "SetResponseData" { MockedHttpInterceptor.setResponse(data) } return nil }
Declaration
Objective-C
extern void APLAutomationMessageReceivedBlock( id _Nullable (^_Nullable message)(NSString *_Nonnull, id _Nullable))
Swift
func APLAutomationMessageReceivedBlock(_ message: ((String, Any?) -> Any?)?)
-
Availability: All.
If
logLevel
isAPLLogLevelDebug
and logging is enabled (see alsoAPLSetLogging
) then logsmsg
with optional parameters to the console. IflogLevel
isAPLLogLevelError
then logsmsg
with optional parameters to the console even if logging is disabled. You should prefer to use APLDEBUG or APLERROR macros for Objective-C. See alsoAPLLogS
for Swift.Declaration
Objective-C
extern void APLLog(APLLogLevel logLevel, NSString *_Nonnull msg, ...)
-
Availability: All.
If
logLevel
is.debug
and logging is enabled (see alsoAPLSetLogging
) then logsmsg
to the console. IflogLevel
is.error
then logsmsg
the console even if logging is disabled. See alsoAPLLog
for Objective-C.Declaration
Objective-C
extern void APLLogS(APLLogLevel logLevel, NSString *_Nonnull msg)
Swift
func APLLogS(_ logLevel: APLLogLevel, _ msg: String)
-
Availability: All.
When
YES
, Appfigurate library debugging messages will be output to the console. The default isNO
. It is best practice to distribute applications via TestFlight and the App Store with logging set toNO
. Also seeAPLLogging
key in theInfo.plist
file.Declaration
Objective-C
extern void APLSetLogging(BOOL logging)
Swift
func APLSetLogging(_ logging: Bool)