Getting the path of an ALAsset

some_id picture some_id · Feb 19, 2011 · Viewed 22.7k times · Source

How can I get the path of each item in an array of ALAssets?

I would like to get the images so that I can add them to an email

e.g.

NSString *path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[mailViewController addAttachmentData:myData mimeType:@"image/png" fileName:@"sample"];

How can this be done?

Answer

Mark Adams picture Mark Adams · Feb 19, 2011

Assuming you already have access to an array of ALAsset objects, you can retrieve their URL like this:

someAsset.defaultRepresentation.url