2012-02-02 29 views
3

我一個虛擬卡(包含在包)複製到普通紙板如下:從UIPasteBoard一個電子名片粘貼到郵件

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

然後,我會喜歡的用戶能夠將其粘貼到電子郵件中。但是,Mail在複製到粘貼板時不提供粘貼選項。我做錯了什麼或郵件不能識別該紙板類型?

回答

0

您只需直接將它添加到消息,像這樣

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]; 
+0

謝謝,但你所回答,這不是問了一個問題。此外,您在答案中指定了錯誤的MIME類型 - 它應該是文本/電子名片 – RunLoop 2012-02-03 06:09:47

+0

抱歉,我誤解了您的問題。我以爲你想把它複製到他們的剪貼板上,然後讓它們粘貼到一個MFMailComposeViewController中,我編輯了MIME。 – shabbirv 2012-02-03 07:34:54

0

代碼中的一切看起來是正確的,因此,如果郵件不會允許您將其粘貼,這意味着郵件不支持粘貼該類型。

編輯:用NSDictionary的嘗試:

UIPasteboard *gpBoard = [UIPasteboard generalPasteboard]; 

NSData *data = [NSData dataWithContentsOfFile:filePath]; 

NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys: 
         data, (NSString *)kUTTypeVCard, 
         nil]; 

gpBoard.items = [NSArray arrayWithObjects:item, nil]; 
+0

我發現當我將vCard複製到另一封電子郵件中並將其粘貼到新郵件中時,確實可以在郵件中粘貼一個vcard。因此,問題不是如果,而是如何。 – RunLoop 2012-02-06 16:47:21

+0

請參閱編輯。你可能想嘗試添加代碼來粘貼工作的vcard,以便檢查它。 – 2012-02-06 17:59:55

+0

也不起作用 – RunLoop 2012-02-06 18:06:57

相關問題