Using the SDK

Set up your app to receive tokens by following these steps:

1. Initialization

To initialize the SDK, copy the following code to the app delegate :

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // some code
    do {
        try YXLSdk.shared.activate(withAppId: clientId)
    } catch {
        // process error
    }
    // some other code
}

@available(iOS 8.0, *)
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    YXLSdk.shared.processUserActivity(userActivity)
    return true
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return YXLSdk.shared.handleOpen(url, sourceApplication: sourceApplication)
}

@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return YXLSdk.shared.handleOpen(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String)
}

2. Authorization

To enable authorization, use the following method:

YXLSdk.shared.authorize()

To receive events with authorization results, you need to add yourself as an observer:

YXLSdk.shared.add(observer: self)

Upon receiving a successful authorization result, the method with the result parameter containing the tokens listed below will be called:

func loginDidFinish(with result: YXLLoginResult) {
    // use result.token and result.jwt
}

If an error occurs, the following will be called:

func loginDidFinishWithError(_ error: Error) {
    // process error
}
  • error: Error with the kYXLErrorDomain domain and YXLErrorCode code.

3. Logout

To delete locally stored tokens, use the following method:

YXLSdk.shared.logout()