Implemented Uniform Type Identifiers and when emailed a single attachment, stringWithContentsOfURL
returns an NSString
with the contents of the file defined by the NSURL
.
When selecting a file from an email with a number of files attached, stringWithContentsOfURL
returns all files attached, with header information, as an NSString
.
Is there a way to open just the selected file?
Update:
- First file user touches, file processed as expected. user can touch as many times and all is good.
- Any subsequent file touched, the email's raw source, minus email header, will be saved as a file represented by the NSURL.
- This behaviour has been observed on iphone 6.0.1 and ipad 5.1.1.
You could parse the raw source and determine which file was selected from the NSURL, potentially problematic I think.
End Update
Code (url in both cases point to a single file). The file extension is *.defects
NSString *file = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
Result for mail with single attachment
"Defect Names"
"Test1 Area"
"Test2 Area"
"Test 3 Area"
"Test 4 Area"
"Extra"
Result for mail with multiple attachments
--Apple-Mail=_785C0CB9-CB2F-43BE-AD5F-D7DEF5F97EFC
Content-Disposition: attachment;
filename=Areas.defects
Content-Type: defects/x-defects;
x-unix-mode=0644;
name="Areas.defects"
Content-Transfer-Encoding: 7bit
"Area of Defect"
"Test1 Area"
"Test2 Area"
"Test 3 Area"
"Test 4 Area"
"Extra"
--Apple-Mail=_785C0CB9-CB2F-43BE-AD5F-D7DEF5F97EFC
Content-Disposition: attachment;
filename="pos.defects"
Content-Type: defects/x-defects;
x-unix-mode=0644;
name="pos.defects"
Content-Transfer-Encoding: 7bit
"Position of Item"
"Test1 Position"
"Test2 Position"
"Test 3 Position"
"Test 4 Position"
"Extra"
...
--Apple-Mail=_785C0CB9-CB2F-43BE-AD5F-D7DEF5F97EFC--