Spren Vision
Spren Vision iOS SDK
installation visit the spren vision ios sdk github repository https //github com/elite hrv/spren vision ios to install the sdk via the swift package manager for more information, see the apple docs for adding package dependencies to your app https //developer apple com/documentation/swift packages/adding package dependencies to your app add a camera usage description to your app's info plist or target info for more information, requesting authorization for media capture on ios https //developer apple com/documentation/avfoundation/cameras and media capture/requesting authorization for media capture on ios and the nscamerausagedescription https //developer apple com/documentation/bundleresources/information property list/nscamerausagedescription apple docs spren ui finger camera example import swiftui import sprenui // create sprenui configuration let config = sprenui config( // api baseurl "https //test api spren com", apikey "\<api key>", // user userid "\<user id>", usergender \<optional, male, female, or other>, userbirthdate \<optional, date>, // ui primarycolor \<optional, color>, // used for buttons secondarycolor \<optional, color>, // used for graphics project fingercamera, // optionally override default intro screen graphics // provide names for image sets in main bundle xcassets // all are required for each project if overriding graphics \[ greeting1 "\<image set name>", // greeting screen 1 greeting2 "\<image set name>", // greeting screen 2 fingeroncamera "\<image set name>", // finger on camera instruction screen nocamera "\<image set name>", // camera access authorization denied screen servererror "\<image set name>" // server or calculation error ], oncancel { // user exited ui before completing a reading // dismiss sprenui }, onfinish { results in // user completed a reading! print(results) // dismiss sprenui } ) // init sprenui view sprenui(config config) body composition example import swiftui import sprenui // create sprenui configuration let config = sprenui config( // api baseurl "https //test api spren com", apikey "\<api key>", // user userid "\<user id>", usergender \<optional, male, female, or other>, userbirthdate \<optional, date>, // ui primarycolor \<optional, color>, // used for buttons secondarycolor \<optional, color>, // used for graphics project bodycomp, // optionally override graphics // provide names for image sets in main bundle xcassets // all are required for each project if overriding graphics \[ setupguide "\<image set name>", servererror "\<image set name>", privacy "\<image set name>", cameraaccessdenied "\<image set name>", incorrectbodyposition "\<image set name>", greetings "\<image set name>", bodyposition "\<image set name>" ], oncancel { // user exited ui before completing a scan // dismiss sprenui }, onfinish { results in // user completed a scan! print(results) // dismiss sprenui } ) // init sprenui view sprenui(config config) sprencapture and sprencore implementation example import sprencapture import sprencore / sprencapture / // configure camera let sprencapture = sprencapture() try? sprencapture start() // set up camera preview preview\ session = sprencapture session / sprencore / // handle prereading compliance checks spren setonprereadingcompliancecheck { check, compliant, action in switch (check, compliant) { case ( framedrop, false) 	 // adjust camera sprencapture dropcomplexity() case ( brightness, ) // optionally update ui to reflect brightness compliance case ( lenscoverage, ) 	 // optionally update ui to reflect lens coverage compliance } } // handle state transitions spren setonstatechange { (state, error) in 	 switch state { 	 case started 	 sprencapture lock() 	 // handle reading started ui update 	 case finished 	 // successful reading! 	 let readingdata = spren getreadingdata() 	 // make post request to the spren api 	 // with readingdata to get insights! 	 case cancelled 	 sprencapture unlock() 	 // handle user cancelled ui update 	 case error 	 sprencapture unlock() 	 // handle error ui update, may be non compliance 	 let description = error localizeddescription 	 } } spren setonprogressupdate { (progress) in // handle progress ui update } sprencapture library sprencapture is where you can initialize a camera preview and first configure the camera this will start a camera session, allow you to add the camera preview to your ui, and handle various other camera controls check out the function definitions below! sprencapture session avcapturesession avcapturesession exposed for ui preview init() throws sets up avcapture session inputs and outputs with the rear wide angle camera func start() starts running the underlying avcapture session func stop() stops running the avcapture session func toggletorch() throws > avcapturedevice torchmode attempts to toggle the torch (flashlight) on returns the resulting torch mode func lock() throws attempts to lock automatic camera settings this should be called when a reading starts func unlock() throws attempts to unlock automatic settings this should be called if autostart will reoccur, i e , when a reading is cancelled or errors func dropcomplexity() throws → bool attempts to drop the computational complexity by reducing the frame rate if frame rate cannot be reduced, dropping the resolution will be attempted this may be called if frame drop is non compliant, i e, exceeds 5% in a 1 second period sprendelegate sprendelegate is an avcapturevideodataoutputsamplebufferdelegate and handles providing frames or notification of frame drop to sprencore sprencore library the sprencore library provides internal control over readings and allows you to gain information on what's going on internally in the sdk so your ui can be updated accordingly here you'll be able to set reading durations, handle progress updates, start and stop readings, and more use this library in conjunction with sprencapture to utilize the full capabilities of spren sdk spren static autostart bool enable or disable reading autostart autostart occurs after 3 seconds of conditions checks compliance static internal(set) var readingdurationseconds double reading duration ≥ 60 seconds or ≤ 240 seconds static func setreadingduration(duration int) set the reading duration a duration in the range ≥ 60 seconds or ≤ 240 seconds must be provided or the call returns static func setonprereadingcompliancecheck(onprereadingcompliancecheck @escaping (compliancecheck name, bool, compliancecheck action?) > void) set a closure to be executed when a compliance check is performed before reading start compliance checks for frame drop, brightness, and lens coverage are performed once per second static setonprogressupdate(onprogressupdate @escaping ( progress double) > void) set a closure to be executed when progress updates progress ranges from 0 to 99 in integer increments state change to finished occurs in lieu of progress update at 100 static func setonstatechange(onstatechange @escaping ( state sprenstate, error error?) > void) set a closure to be executed when state changes occur, i e , started , finished , cancelled , and error static func startreading() manually start the reading static func cancelreading() manually stop the reading static func getreadingdata() > string? after spren transitions to finished, reading data may be retrieved to hit the spren api for results see the https //docs spren com/user and sdk data post endpoint for more information if not using sprencapture if you'd like to use your own library or code to handle camera configurations and initialization, make sure to reference this section and the sprendelegate section to get more context and see what functions need to be implemented reference sprendelegate static func process(frame sprenframe) provide a frame for processing static func framedropped() record frame drop sprenframe created from received media buffers, e g sprenframe(samplebuffer samplebuffer, orientation connection videoorientation rawvalue) compliance checks compliancecheck static func setonprereadingcompliancecheck(onprereadingcompliancecheck @escaping (compliancecheck name, bool, compliancecheck action?) > void) compliance checks are run at 1 second intervals as frames are provided, i e , if internally to sprencore the time when the frame is received is >1 second later than the last check for compliancecheck name framedrop frame drop must be less than 5% during one second and at least 60 frames must be received during the initial setup of sprencapture, frame drop may be high; so, we suggest ignoring the first frame drop noncompliance before any camera reconfiguration brightness enough ambient light must be received, torch (flashlight) is recommended brightness checks also provide a compliancecheck action , either increase or decrease lenscoverage finger must cover lens with light pressure sprencomplianceerror static func setonstatechange(onstatechange @escaping ( state sprenstate, error error?) > void) readings error if noncompliance of any check occurs for 5 consecutive seconds if this occurs, re enable autostart to start the compliance check and reading process over again framedrophigh brightnesslow brightnesshigh lenscoverage