【问题标题】:Paste a vCard from UIPasteBoard into Mail将 UIPasteBoard 中的 vCard 粘贴到邮件中
【发布时间】:2012-02-25 10:11:28
【问题描述】:

我将 vcard(包含在捆绑包中)复制到通用粘贴板上,如下所示:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"AM" ofType:@"vcf"]; 
NSData *data = [NSData dataWithContentsOfFile:filePath];
[[UIPasteboard generalPasteboard] setData:data forPasteboardType:(NSString*)kUTTypeVCard];

然后我希望用户能够将其粘贴到电子邮件中。但是,当已将其复制到粘贴板时,Mail 不提供粘贴选项。是我做错了什么还是 Mail 无法识别该粘贴板类型?

【问题讨论】:

    标签: iphone ios cocoa-touch ipad


    【解决方案1】:

    您可以像这样直接将其添加到消息中

    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"AM ofType:@"vcf"]; 
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    [mailViewController addAttachmentData:data mimeType:@"text/vcard" fileName:@"AM.vcf"];
    mailViewController.mailComposeDelegate = self;
    [self presentModalViewController:mailViewController animated:YES];
    [mailViewController release];
    

    【讨论】:

    • 谢谢,但您正在回答一个没有被问到的问题。此外,您在答案中指定了错误的 mime 类型 - 它应该是 text/vcard
    • 对不起,我误解了你的问题。我以为您希望将其复制到他们的剪贴板上,然后让他们将其粘贴到 MFMailComposeViewController 中,我已经编辑了 mime。
    【解决方案2】:

    您的代码中的所有内容看起来都是正确的,因此如果 Mail 不允许您粘贴它,则意味着 Mail 不支持粘贴该类型。

    编辑:用 NSDictionary 试试:

    UIPasteboard *gpBoard = [UIPasteboard generalPasteboard];
    
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    
    NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:
                          data, (NSString *)kUTTypeVCard,
                          nil];
    
    gpBoard.items = [NSArray arrayWithObjects:item, nil];
    

    【讨论】:

    • 我发现确实可以在邮件中粘贴 vcard,因为我将 vcard 复制到另一封电子邮件中并将其粘贴到新邮件中。因此,问题不是如果,而是如何。
    • 查看编辑。您可能想尝试添加代码以粘贴到工作 vcard 中,以便检查它。
    • 编写一些粘贴代码,粘贴到该工作 vcard 中,然后在调试器中查看。应该是有启发性的。
    猜你喜欢
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多