您对 UIActivityViewController 的控制非常有限,但如果您附加了众所周知的 mime 类型,我发现您可以通过在文件 URL 中提供关联的文件扩展名来使其正常工作。例如,如果您的附件是 vCard,请在文件 URL 中使用“.vcf”扩展名:
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// The file extension is important so that some mime magic happens!
NSString *filePath = [docsPath stringByAppendingPathComponent:@"vcard.vcf"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
[data writeToURL:fileUrl atomically:YES]; // save the file
// Now pass the file URL in the activity items array
UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:
@[@"Here's an attached vCard", fileUrl] applicationActivities:nil];
[vc presentModalViewController:avc animated:YES];