2

URLからPDFを保存して、メールで送信しようとしています。送信者はそれを持っているようですが、受信者はそれを取得しません。

私がするとき私NSLogNSString file得る/var/mobile/Applications/0ADE222E-6346-4C6C-8348-DA5327B980AA/Documents/myPDF.pdf

保存しているようですが、送信しません。保存して送信するための以下のコードは次のとおりです

編集

更新されたコード

    // This pdfURL is 0 bytes
    NSData *pdfURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",webPage.urlString]]];

    //Store the Data locally as PDF File
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [paths objectAtIndex:0];
    NSString *file = [documentDirectory stringByAppendingFormat:@"/myPDF.pdf"];

    [pdfURL writeToFile:file atomically:YES];

    //Sending the pdf
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    composer.mailComposeDelegate = self;        
    if ([MFMailComposeViewController canSendMail]){
        //Changed email for privacy issues
        [composer setToRecipients:[NSArray arrayWithObjects:@"123@abc.com", nil]];
        [composer setSubject:[NSString stringWithFormat:@"%@ email",titleText]];
        [composer setMessageBody:@"your custom body content" isHTML:NO];

        NSLog(@"pdf %@",file);
        // This pdfData is 0 bytes
        NSData *pdfData = [NSData dataWithContentsOfFile:file];

        [composer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"myPDF.pdf"];

        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentModalViewController:composer animated:YES];            
    }
4

2 に答える 2

1

URLからのものである場合は、NSDataに保存します。

NSData *pdfData = [NSData dataWithContentsOfURL[NSURL URLWithString:@"URL Of Pdf"]];

そしてそれをメールに添付します

于 2012-07-13T16:28:00.970 に答える
0

問題は、webPage.urlStringが空であることにありました。このコードは、URL文字列が空でないことを確認するだけで機能します:P

于 2012-07-13T14:40:30.860 に答える