Record Events

Native iOS ==> Core framework

When VLDSession uploads a record it will send an NSNotification. To listen for this notification add an observer to the NSNotificationCenter with the constant kVLDInformRecordSubmittedNotification.

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

When the notification is posted the object property of the notification will contain the VLDInformRecord object uploaded.

@objc func recordDidUpload(_ notification: Notification) {
    guard let record = notification.object as? VLDInformRecord else {
        return
    }
}

If a 400 error is returned from the server, the record will be discarded and an NSNotification will be posted. To listen for this notification, add an observer to the NSNotificationCenter with the constant kVLDInformRecordSubmissionFailedNotification.

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

The object property of the notification will contain the invalid VLDInformRecord object. The userInfo dictionary for this notification will contain one key, error with the NSError object for the failed upload.

@objc func recordSubmissionDidFail(_ notification: Notification) {
    guard let userInfo = notification.userInfo as? [String: Any],
        let error = userInfo["error"] as? NSError,
        let record = notification.object as? VLDInformRecord else {
            return
    }
    print("Record submission failed with error: \(error)")
    print("Record: \(record)")
}