You are creating the URL incorrectly. You need to use fileURLWithPath
, not URLWithString
.
Also, this:
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",[directoryContents objectAtIndex:indexPath.row]]];
Should be:
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:[directoryContents objectAtIndex:indexPath.row]];
There is no need for the string format.
Last thing. Th file name passed to the addAttachment
method should be just a file name, not a full pathname.