Reputation: 1287
I write a file named "test.own" to Document path, and I get its URL.
Now I have a button and what I want is to open an options sheet dialog in which there is Email or others to send or open my file when I click the button.
Is there anyway to achieve this ?
Thanks in advance!
Upvotes: 2
Views: 156
Reputation: 11276
When the file is selected do this.
- (IBAction)showFileOptions:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select a option"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"email file",@"open file"];
[actionSheet showInView:self.view];
}
Write delegate to handle the actionSheet:
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex
{
if (buttonIndex == 0) {
//email
[self emailDocument];
}
else if (buttonIndex==1)
{
//open file
}
}
Emailing document:
-(void)emailDocument
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Your own subject"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach your .own file to the email
//add conversion code here and set mime type properly
NSData *myData =[NSData dataWithContentsOfURL:[NSURL urlWithString:pathToOwnFile]];
[picker addAttachmentData:myData mimeType:@"SETMIMETYPEACCORDINGLY" fileName:@"example.own"];
// Fill out the email body text
NSString *emailBody = @"PFA";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
Upvotes: 2
Reputation: 89509
For e-mail, all you need to do is present the MFMailComposeViewController view and then you can add your ".own
" custom document via that view controller's addAttachmentData:mimeType:fileName:
method.
(I would link to Apple's documentation except Apple's documentation website appears to be down as I am typing this).
As for the other part of your question, other apps normally use the UIDocumentInteractionController to display a "Open in..." dialog, except the other apps need to know how to open your custom document (which they won't be able to do if your app isn't too big or famous or if somebody else -- who is not -- you authored it).
Upvotes: 1