Functions

The following functions are available globally.

  • Availability: iOS apps only.

    You must call APLApplicationDidFinishLaunchingWithOptions() in your app delegate’s application: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’s application: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 delegate applicationDidFinishLaunching method.

    Objective-C example

    - (void) applicationDidFinishLaunching {
        APLApplicationDidFinishLaunching();
    }
    

    Swift example

    func applicationDidFinishLaunching() {
      APLApplicationDidFinishLaunching()
    }
    

    Declaration

    Objective-C

    extern void APLApplicationDidFinishLaunching()

    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 the APLSessionDidReceiveMessage() function from within your session:didReceiveMessage:replyHandler: method (see examples below). If your watch app does not have its own WCSessionDelegate then you do not need to do anything - Appfigurate library installs a WCSessionDelegate and calls APLSessionDidReceiveMessage() 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()

    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: 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(observer).

    Declaration

    Objective-C

    extern id<NSObject> _Nonnull APLAddConfigurationUpdatedBlock(
        APLConfigurationUpdatedBlock _Nonnull block)

    Swift

    func APLAddConfigurationUpdatedBlock(_ block: @escaping APLConfigurationUpdatedBlock) -> 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: 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(block).

    Declaration

    Objective-C

    extern void APLRemoveConfigurationUpdatedBlock(id<NSObject> _Nonnull observer)

    Swift

    func APLRemoveConfigurationUpdatedBlock(_ observer: NSObjectProtocol)
  • Availability: All.

    When YES, Appfigurate library debugging messages will be output to the console. The default is NO. It is best practice to distribute applications via TestFlight and the App Store with logging set to NO. Also see APLLogging key in the Info.plist file.

    Declaration

    Objective-C

    extern void APLSetLogging(BOOL logging)

    Swift

    func APLSetLogging(_ logging: Bool)
  • 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()

    Swift

    func APLSaveConfiguration()
  • Availability: All.

    Restores the configuration from temporary storage back into the keychain. See APLSaveConfiguration() for more details and usage example.

    Declaration

    Objective-C

    extern void APLRestoreConfiguration()

    Swift

    func APLRestoreConfiguration()
  • Availability: All.

    The application or framework that links in AppfigurateLibrary.xcframework must define a function with the following prototype that returns the Class (Obj-C) or AnyClass (Swift) of your APLConfiguration 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()

    Swift

    func APLConfigurationClass() -> AnyClass