Authentication

Native iOS ==> Core framework

Authenticating requests with the Validic API requires a Validic Mobile User to be provisioned and with a Validic Mobile User Token. Further documentation for creating Validic Mobile Users is available in Provisioning and Managing Users.

You will need to provision the user from your server or your mobile app.

Session Overview

VLDSession stores a user, their settings (e.g. Bluetooth subscribed peripherals, HealthKit subscriptions) and all pending record uploads. This data is persisted between app launches but is deleted if endSession is called.

VLDSession is a singleton object and must be accessed by its sharedInstance method. The different frameworks of the Native iOS Inform Mobile SDK rely on a valid user existing in the current VLDSession singleton object.

Starting a session

To start a VLDSession you will need a VLDUser object. A Validic user can be provisioned using the Validic API - documentation is available for the Inform API. The credentials needed are a Validic user ID, an organization ID, and a user access token.

let user = VLDUser(validicUserID:"user_id", organizationID:"organization_id", accessToken:"access_token")

The user object is then passed to the startSessionWithUser: method.

VLDSession.sharedInstance().start(with: user)

Note: It is required to use valid Validic credentials. The validicUserID, organizationID, and accessToken properties will be sent to the server for validation at the start of any user session. Sessions started with invalid or unknown user credentials (i.e. any credentials not provisioned by the Inform API) will be ended automatically.

Session End Notification

When a VLDSession is ended, it will post an NSNotification. To listen for this notification add an observer to NSNotificationCenter with the constant kVLDSessionEndedNotification.

NotificationCenter.default.addObserver(self, selector: #selector(sessionDidEnd(_:)), name: NSNotification.Name.vldSessionEnded, object: nil)

When the notification is posted, the userInfo property of the notification will be a dictionary containing validicUserID, organizationID, and informRecords keys. Note: when transitioning from the v1.x.x to v2.x.x Validic Mobile Library, an additional record key may be included, which contains any unsynced v1-formatted records.

@objc func sessionDidEnd(_ notification: Notification) {
    guard let sessionInfo = notification.userInfo as? [String:Any] else {
        return
    }
    let userID = sessionInfo["validicUserID"] as? String ?? ""
    let organizationID = sessionInfo["organizationID"] as? String ?? ""
    let unsyncedInformRecords = sessionInfo["informRecords"] as? Array<VLDInformRecord> ?? []
    NSLog("Session ended for user %@ of organization %@, with %i unsynced records.", userID, organizationID, unsyncedInformRecords.count)
}

Best Practices

Check for an existing user in VLDSession before performing core logic related to your app.

guard let _ = VLDSession.sharedInstance().user else {
    showLoginScreen()
    return
}

Starting a session will delete the current session if it exists, clearing the existing user's data and any queued records that haven't been uploaded.