2013-01-18 79 views
0

我正在构建一个应用程序,允许用户导出导入数据文件并通过电子邮件发送它们。HandleOpenURL with multiple pathExtension

所以我创建了扩展名为“.myAppExtension”的数据文件类型。

第一次一切顺利。我无法导出和发送电子邮件。当我打开电子邮件时,该方法确实起作用。

-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url { 

if (url != nil && [url isFileURL]) { 
    NSLog(@"%@",url); 
    NSLog(@"%@",[url pathExtension]); 

    if([[[url pathExtension] lowercaseString] isEqualToString:[@"myAppExtension" lowercaseString]]){ 
     //Deal with received file 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Export ok" message:[NSString stringWithFormat:@"This file has been added : %@",[url lastPathComponent]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil,nil]; 
     [alert show]; 
    }else{ 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Export failed" message:[NSString stringWithFormat:@"This extention is not supported : %@",[url pathExtension]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil,nil]; 
     [alert show]; 
    } 

} 
return YES; 
} 

我的问题是,当我想导出扩展名为“otherExtension”的其他类型的文件。我没有在我的应用程序中为此扩展创建数据类型。

因此,我导出并发送一个电子邮件与第二种类型的文件。文件名显示在电子邮件“file.otherExtension”中。但是,这是问题,当我点击这个邮件附件时,电子邮件应用程序提供给我在我的应用程序中打开它。这不是我想要的,正如我所说的,我没有为“otherExtension”创建数据类型。

编辑:这是我创造了对myApp-的info.plist文件类型:

enter image description here

回答

0

如果有人有兴趣,这个问题是从发送电子邮件fonction。

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init] ; 
[picker setSubject:mailSubject]; 
[picker addAttachmentData:codedData mimeType:@"application/myApp" fileName:[filePath lastPathComponent]]; 
[picker setToRecipients:[NSArray array]]; 
[picker setMessageBody:mailBody isHTML:NO]; 
[picker setMailComposeDelegate:self]; 
[currentMainViewController presentViewController:picker animated:YES completion:nil]; 

通过向邮件附件添加MIME类型,接收应用程序正在使用它来读取文件。用“无”替换MIME类型解决了我的问题。

[picker addAttachmentData:codedData mimeType:nil fileName:[filePath lastPathComponent]];