Sample code for 30+ languages & platforms
Objective-C

Update a String Property in XMP

See more XMP Examples

Demonstrates how to open a JPG or TIF image file, access the XMP metadata, and update the value of a string property. (If the string property does not already exist, it is created.)

Chilkat Objective-C Downloads

Objective-C
#import <CkoXmp.h>
#import <CkoXml.h>

BOOL success = NO;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoXmp *xmp = [[CkoXmp alloc] init];

// Load a JPG or TIF image file.
success = [xmp LoadAppFile: @"qa_data/xmp/AJ_123642_1511.tif"];
if (success != YES) {
    NSLog(@"%@",xmp.LastErrorText);
    return;
}

NSLog(@"%@%d",@"Num embedded XMP docs: ",[xmp.NumEmbedded intValue]);

// This example assumes that XMP metadata is already present in the image file.
if ([xmp.NumEmbedded intValue] == 0) {
    NSLog(@"%@",@"No XMP metadata already exists..");
    return;
}

// Get the XMP metadata.
CkoXml *xml = 0;
xml = [xmp GetEmbedded: [NSNumber numberWithInt: 0]];

// Show the XML:
NSLog(@"%@",[xml GetXml]);

// Update (overwrite) a string property.
[xmp AddSimpleStr: xml propName: @"NumberofTimes" propVal: @"123"];

success = [xmp SaveAppFile: @"qa_output/updated.tif"];
if (success != YES) {
    NSLog(@"%@",xmp.LastErrorText);
    return;
}

NSLog(@"%@",@"Success.");