Once calibration data is taken, the user can scan. The following code sample takes a scan:

__weak typeof(&*self)weakSelf = self;
    [[CPScioDevice sharedInstance] isCalibrationValid:^(BOOL success) {
        if (!success) {
            [weakSelf alertWithTitle:@"Calibration is invalid" message:@"Calibrate before scan"];
            return;
        }
        [weakSelf toastWithTitle:@"scanAPI" message:@"Scanning"];
        [[CPScioDevice sharedInstance] scanWithCompletion:^(BOOL success, CPScioReading *reading, NSError *error) {
            NSLog(@"Scan: %i",success);
            if (!success) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self alertWithTitle:error.userInfo[NSLocalizedDescriptionKey] message:error.userInfo[NSLocalizedFailureReasonErrorKey]];
                });
                return;
            }
            weakSelf.scanReading = reading;
            if (![SASampleFileUtils storeToDisk:reading fileName:SALastScanFileName]) {
                [self alertWithTitle:@"Failure" message:@"Failed to save last scan"];
            }
            
            [self toastWithTitle:@"Scan Completed" message:@"You can analyze a model now."];
        }];
    }];

Cached scans
Scans can be stored locally (for uploading for analysis in the server later).
SampleFileUtils class allows you to store a scan object, and read and remove from local storage, using the following methods:

storeToDisk
This method has the following parameters:

  • Object- this is the scan object (CPScioReading).
  • fileName- to store the scan.

The method returns a boolean response for success/failure.

readArchiveWithFileName
This method has only one parameter:

  • fileName- of the scan that had been stored earlier.

The method returns a CPScioReading object of the scan.

removeFromDiskFileName
This method has only one parameter:

  • fileName- of the scan that had been stored earlier.

The method returns an NSError object that contains the error in case of a failure, or nil for success.

The following code sample stored a CPScioReading object (“_reading”)

[SampleFileUtils storeToDisk:_reading fileName:weakSelf.scanFileName];

The following code sample loads a CPScioReading object

CPScioReading *lastScan = [SampleFileUtils readArchiveWithFileName:self.scanFileName];