iOS版:我怎样才能在代码
打开我自己的文件格式(如.own)我写了一个名为“test.own”到文件的路径,我也得到了URL。iOS版:我怎样才能在代码
现在我有一个按钮,我要的是打开一个选项表对话框,其中有电子邮件或他人发送或打开我的文件当我点击按钮。
无论如何要实现这一目标吗?
在此先感谢!
对于电子邮件,您只需提供MFMailComposeViewController视图,然后您可以通过该视图控制器的addAttachmentData:mimeType:fileName:
方法添加您的“.own
”自定义文档。
(我会链接到苹果的文档,除了苹果的文档网站似乎是因为我输入这个)。
至于你的问题的其他部分,其他应用程序通常使用UIDocumentInteractionController来显示“打开在...”对话框,除了其他应用程序需要知道如何打开您的自定义文档(他们不会如果你的应用程序不是太大或不出名,或者其他人 - 不是 - 你创作的)。
感谢@satheeshwaran您的答案。 – 2013-04-07 09:37:36
当选择文件时,请执行此操作。
- (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];
}
写委托来处理actionSheet:
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex
{
if (buttonIndex == 0) {
//email
[self emailDocument];
}
else if (buttonIndex==1)
{
//open file
}
}
通过电子邮件发送文件:
-(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];
}
+1给你......我想你可能比我更了解Rocky的问题! – 2013-04-07 09:03:58
@MichaelDautermann谢谢,但你的回答让我改进了我的+1。 – satheeshwaran 2013-04-07 09:12:44
BTW很好的问题。 – satheeshwaran 2013-04-07 09:14:03