Representation

Representations are the primary means of interacting with Payloads in DM SDK 2.0 and above. They allow an app to request data in the format that it wants to handle. For instance, if an app wants to process UPC A barcodes, it can request a Payload representation of UPC_A. If a Payload can be expressed that way, a string containing the UPC A code value will be returned, otherwise null. It doesn’t matter what code type this data came from, whether it was a UPC A barcode, a Digimarc digital watermark, or something else. If the data can be represented as a UPC A barcode, it will be returned that way. This simplifies application code because it allows an application to request specific types of data and ignore all others.

iOS

if let value = Payload.representations[.QRCode] {
  //handle value as the contents of a QR code
} else if let value = Payload.representations[.GTIN14] {
  //handle value as a GTIN14
} else if Payload.representations[.ImageDigimarc] != nil {
  resolver.resolve(Payload, queue: OperationQueue.main, completionBlock: { (resolvedContent, error) in {
    //handle the result through resolvedContent
  }
}
Note

This sample code is provided as general guidance. Swift versions might result in required code updates which might not be reflected in this document. If you copy/paste code snippets, be aware that line breaks and other formatting might change.

Android

// This is a general purpose example that tries to handle multiple different types separately
//
private void handleImageDecode( List< ReadResult > results )
{
  for ( ReadResult next : results )
  {
    String value;
    Payload Payload = next.getDecodedPayload();
    if ( ( value = Payload.getRepresentation( Payload.BasicRepresentation.QRCode )) != null )
    {
      // value contains the content of the QR Code
      // App will generally launch this content
    }
    else if ( ( value = Payload.getRepresentation( Payload.BasicRepresentation.GTIN_14 )) != null )
    {
      // value contains a GTIN 14 which could have come from a Digimarc Barcode or one of
      // multiple different 1D barcode types
      // App can handle this case as required - look up pricing, inventory, etc.
    }
    else if ( ( value = Payload.getRepresentation( Payload.BasicRepresentation.Image_Digimarc )) !=
null )
    {
      // value contains a Digimarc Barcode does not hold a packaging ID (GTIN 14).
      // App will call the Digimarc Resolver
      mResolver.resolve( Payload );
    }
    // The app doesn’t care about other types & if the result wasn’t handled by any of the
    // cases above it will be ignored.
  }
}