iOS:如何在代码中打开自己的文件格式(如.own)

iOS:如何在代码中打开自己的文件格式(如.own),ios,objective-c,xcode,Ios,Objective C,Xcode,我将一个名为“test.own”的文件写入文档路径,并获取其URL 现在我有了一个按钮,我想打开一个选项工作表对话框,其中有电子邮件或其他人要发送或打开我的文件 有没有办法做到这一点 提前谢谢 对于电子邮件,您只需显示MFMailComposeViewController视图,然后可以通过该视图控制器的addAttachmentData:mimeType:fileName:方法添加您的“.own”自定义文档 (我会链接到苹果的文档,但在我打字时,苹果的文档网站似乎关闭了) 至于你问题的另一部分,

我将一个名为“test.own”的文件写入文档路径,并获取其URL

现在我有了一个按钮,我想打开一个选项工作表对话框,其中有电子邮件或其他人要发送或打开我的文件

有没有办法做到这一点


提前谢谢

对于电子邮件,您只需显示MFMailComposeViewController视图,然后可以通过该视图控制器的
addAttachmentData:mimeType:fileName:
方法添加您的“
.own
”自定义文档

(我会链接到苹果的文档,但在我打字时,苹果的文档网站似乎关闭了)


至于你问题的另一部分,其他应用程序通常使用UIDocumentInteractionController来显示“Open in…”对话框,但其他应用程序需要知道如何打开你的自定义文档(如果你的应用程序不是太大或太有名,或者如果其他人不是你编写的,他们将无法打开).

选择文件后,请执行此操作

- (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];
}
编写代理以处理操作表:

- (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:@"first@example.com"]; 
  NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
  NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

 [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祝你。。。我想你可能比我更了解洛基的问题@MichaelDautermann谢谢你,但是你的回答让我提高了一点,所以+1。