2014-07-03 86 views
0

我已經做了一個PDF文件,我試圖附加它的電子郵件,但文件沒有得到附加事實上文件名不是什麼,它是假設是。以下是我的代碼在iOS中的電子郵件中附加PDF文件

- (IBAction)btnAttachPDF:(id)sender { 


if ([MFMailComposeViewController canSendMail]) 
{ 

    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 

    mailer.mailComposeDelegate = self; 

    [mailer setSubject:@"video"]; 

    NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil]; 
    [mailer setToRecipients:toRecipients]; 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *fileName; 
    fileName = [[NSString alloc]initWithFormat:@"%@.pdf", lblName.text]; 

lblName.text想給我的回報,我已經進入,但它僅僅是pdf格式,但如果我給它它存儲硬編碼值的文件的名字可以說,我的文件名給它一個名字@「rio.pdf」,但後來在文件中沒有附加。

NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName]; 
    NSMutableData *myPdfData = [NSMutableData dataWithContentsOfFile:pdfFileName]; 
    [mailer addAttachmentData:myPdfData mimeType:@"application/pdf" fileName:fileName]; 


    [self presentViewController:mailer animated:YES completion:nil]; 




} 



else 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                message:@"Your device doesn't support the composer sheet" 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    [alert show]; 

} 

}

+0

[pdf作爲iOS設備中的電子郵件附件]的可能副本(http://stackoverflow.com/問題/ 8846338/pdf-as-an-email-attachment-in-ios-device) –

+0

你是否正確地在xib中鏈接了你的「lblName」標籤,看起來像是null。你可以嘗試記錄NSLog(@「%@」,lblName); – rishi

+0

@DarshanKunjadiya更好地打開他在問題中給出的鏈接,它甚至不存在:/ –

回答

1

實際NSSearchPathForDirectoriesInDomains返回的路徑是不準確的。它返回的最後一個組件是/ Documents,而文件被保存在/Documents/temp/filename.pdf