Links
Comment on page

Swift

Output source code snippets

In Appfiguate Simulator app, under the SWIFT/IOS LIBRARY INTEGRATION section:
Tap Output implementation then tap Console.
Tap Output UIAppDelegate snippet then tap Console.
Tap Output UIWindowSceneDelegate snippet then tap Console.
Tap Output Info.plist snippet then tap Console.
The output will appear in the macOS Console.app . Select the iOS Simulator device in the left hand pane. Type process:appfigurate in the search box in the top right.

Create APLConfiguration subclass

In your app, add a new Swift class, subclassing APLConfiguration, called Configuration.
In your apps Configuration.swift file, paste the .swift implementation file output to the Console in Output source code snippets.
Note: your public key output to the Console in Output source code snippets will be different to the public key in the following example.
import Foundation
import AppfigurateLibrary
@objcMembers class Configuration: APLConfiguration {
@BoolProperty(description: "Log debug output to console", restart: false)
var debugLogging: Bool
@StringPropertyListEdit(regex: #"https://[\w\.-]+\.yourappserver.com/.*"#, description: "Application server url", restart: false, values: ["Dev":"https://dev.yourappserver.com/api", "Prod":"https://www.yourappserver.com/api"])
var serverURL: String
override func allowInvalidSignatures() -> Bool {
return !ENCRYPTED()
}
override func publicKey() -> String {
// 41 36 87 71 0D 05
return "-----BEGIN PUBLIC KEY-----\n" +
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4TZnKfGeXttN7Rr3eiAZ\n" +
"PMEPsZvbo7lgIpMh6OjgBsoqkJJP0yXXLtpqsBCv8vm7RYqCn5+yfkiCQiXvkJBz\n" +
"FSKmLF9EPR9l1H+32Id82dDuseD70D66puPUHjciEgmU18DpW2NVvTAykMwTEsiR\n" +
"0h/ExBEhUe75qtwlVno8cMFbEfVtiGbKECvWIr122ED71T0Jt2Bcxqx1a7c1hPIV\n" +
"RwLxIfWfE0+2rB9nJVPBgsTVPywibDvjio82FousyMDmvkAbMq5iyuyvJ0+5bATz\n" +
"o12GEt5lSiQlCMzfmkWYBROMDCh27qGFVVo1XAUCVsMfsW9n4iQcoLAdUp/LI3B3\n" +
"ywIDAQAB\n" +
"-----END PUBLIC KEY-----\n";
}
override func reset() {
debugLogging = true
serverURL = "https://www.yourappserver.com/api"
}
}
@_cdecl("APLConfigurationClass")
func APLConfigurationClass() -> AnyClass {
return Configuration.self
}
The APLConfigurationClass function with C calling convention must be implemented in your app otherwise a linker error will be issued. The recommended place to implement is at the bottom of your APLConfiguration subclass.

Edit Info.plist

In your apps Info.plist file (right click, Open As ‣ Source Code). Paste the Info.plist snippet output to the Console in Output source code snippets.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>appfigurate.quickstart</string>
<key>CFBundleURLSchemes</key>
<array>
<string>quickstart</string>
</array>
</dict>
</array>
If you already have an existing CFBundleURLTypes array in your Info.plist file, then insert just the <dict> ... </dict> portion.

Update UIApplicationDelegate

In your apps AppDelegate.m file, include calls to APLApplicationOpenURL and APLDidFinishLaunchingWithOptions. Paste the UIApplicationDelegate snippet output to the Console in Output source code snippets.
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return APLApplicationOpenURL(url)
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
APLApplicationDidFinishLaunchingWithOptions(launchOptions)
return true
}

Update UIWindowSceneDelegate

If your app targets iPadOS 13+, in your apps SceneDelegate.m file, include a call to APLApplicationOpenURL. Paste the UIWindowSceneDelegate snippet output to the Console in Output source code snippets.
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
APLApplicationOpenURL(url)
}
}

Test your configuration

To test that you've successfully updated your app to use Appfigurate:
Compile and run Quickstart to the same Simulator instance that Appfigurate Simulator was run from previously.
Press Shift-Cmd-H to get back to the Simulator home screen.
Tap the Appfigurate app icon.
Tap the Quickstart row. The Simulator screen will briefly flicker as it swaps to the Quickstart app, reads its configuration and swaps back to Appfigurate.
Appfigurate will now be displayed and showing the following screen:
  • Since we added a @BoolProperty for debugLogging and @StringPropertyListEdit for serverURL, you can now change these configuration items at runtime. Tap Apply⌄ to apply the configuration to the Quickstart app.