2014-07-21 14 views
-2

我正在開發一個iOS應用程序。我是iOS中的文件操作的新手。我想發送電子郵件,分享和打印每個PDF文件。這些pdf文件被捆綁在一起。如何發郵件,分享和打印pdf?

在我的視圖控制器,我創建了3個按鈕:

  1. 電子郵件
  2. 的iBooks
  3. 打印

我應該怎麼做才能實現這些操作?

+0

使用SLComposeViewController爲[電子郵件支持(https://developer.apple.com/library/ios/documentation/NetworkingInternet /Reference/SLComposeViewController_Class/Reference/Reference.html) –

+0

[你的問題太寬泛了](https://stackoverflow.com/help/how-to-ask)。在問這裏之前,您是否嘗試使用Google搜索教程/示例?如果是這樣,你嘗試了什麼? –

+0

我用UIDocumentInteractionControllerDelegate,它解決了我的問題。 – Hawkman

回答

0

這可能爲電子郵件是helpgul你:

首先,在你的應用程序中導入MessageUI.framework

而您的設備或模擬器必須配置您的一個電子郵件帳戶。

然後,您的電子郵件按鈕單擊事件會是這個樣子:

-(void)ClickOnEmailUs 
{ 
    MFMailComposeViewController *picker; 
    picker = [[MFMailComposeViewController alloc] init]; 
    if(picker) 
    { 
     if ([MFMailComposeViewController canSendMail]) 
     { 
      picker.mailComposeDelegate = self; 
      [picker setToRecipients:receipientsArrayOfStrings]; 
      [picker setSubject:@"Your Subject"]; 
      [picker setMessageBody:@"E-Mail Body" isHTML:YES]; 
      [picker addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"file.pdf"]; // for adding attachment to the mail 
      [self.navigationController presentModalViewController:picker animated:YES]; 
     } 
     else 
     { 
      UIAlertView *noEmailAccountMsg = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Please configure your email account." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [noEmailAccountMsg show]; 
     } 
    } 
} 
+0

將此行添加到上面的代碼中,直到出現MFMailComposer之前。 \t [vc addAttachmentData:pdfData mimeType:@「application/pdf」fileName:@「file.pdf」]; 這將有助於附件 – Geet