5

I've tried sharing an NSData object of the file contents, and the activity view comes up with the mail option, and then the mail compose controller displays, but there's no attachment.

I've tried sharing an NSUrl with the path of the file, but in that case when the activity view comes up it takes up the whole screen but is blank except for the "cancel" button at the bottom. Weird. Also the activity view only comes up on the device in this case, it never even comes up on the simulator.

If I convert the NSData to an NSString, then it does work, but it just pastes the string into the body of the email. I don't want that, I want to attach a file.

I've used the debugger to verify that the NSData object has (the correct) data and that the NSUrl object has the right file path. No dice.

        var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        var file = Path.Combine(documents, "file.txt");
        NSData dataToShare = NSFileManager.DefaultManager.Contents(file);

        UIActivityViewController activityViewController = new UIActivityViewController(new NSObject[] { dataToShare }, null); //Email comes up but data isn't attached

        // OR

        UIActivityViewController activityViewController = new UIActivityViewController(new NSObject[] { new NSUrl(file) }, null); //Activity view takes up the whole screen and is blank

        // OR

        UIActivityViewController activityViewController = new UIActivityViewController(new NSObject[] { (NSString)dataToShare.ToString() }, null); //Pastes string into email body
Aurast
  • 1,427
  • 13
  • 21
  • Do you just want to send e-mail with an attachment? Then why not use the MFMailComposer in your app instead? – Jason Feb 27 '14 at 20:00
  • 2
    No I want it to be available to all apps that can handle it, but I've been testing it with email – Aurast Feb 27 '14 at 20:21
  • That may be normal behavior. Offhand I don't have any apps that I know of that handle text files that I could test with. – Jason Feb 28 '14 at 01:44

0 Answers0