iphone - How to attach a PDF file to mail and send mail in iOS -
iphone - How to attach a PDF file to mail and send mail in iOS -
currently developing expense management app , want attach pdf file mail service , send specified email address. guide me should start , how develop it.
thanks.
mfmailcomposeviewcontroller *vc = [[mfmailcomposeviewcontroller alloc] init]; vc.mailcomposedelegate = self; [vc setsubject:@"monthly expense report"]; [vc addattachmentdata:pdfdata mimetype:@"application/pdf" filename:[nsstring stringwithformat:@"%@.pdf",[arrofexpensedate objectatindex:1]]]; if ([mfmailcomposeviewcontroller cansendmail]) { [self presentviewcontroller:vc animated:yes completion:nil]; }
i have created illustration on how send pdf attachment using mfmailcomposeviewcontroller. next code :
@interface viewcontroller () <mfmailcomposeviewcontrollerdelegate> @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; } - (ibaction)compseemail:(id)sender { if ([mfmailcomposeviewcontroller cansendmail]) { mfmailcomposeviewcontroller *vc = [[mfmailcomposeviewcontroller alloc] init]; vc.mailcomposedelegate = self; [vc setsubject:@"monthly expense report"]; nsstring *pdfpath = [[nsbundle mainbundle] pathforresource:@"apacheinstallationsteps" oftype:@"pdf"]; nsdata *pdfdata = [nsdata datawithcontentsoffile:pdfpath]; [vc addattachmentdata:pdfdata mimetype:@"application/pdf" filename:@"apacheinstallationsteps.pdf"]; [self presentviewcontroller:vc animated:yes completion:nil]; } else { uialertview *erroralert = [[uialertview alloc] initwithtitle:@"alert!!!" message:@"your device can't send emails." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil]; [erroralert show]; } } - (void)mailcomposecontroller:(mfmailcomposeviewcontroller*)controller didfinishwithresult:(mfmailcomposeresult)result error:(nserror*)error { // notifies users errors associated interface switch (result) { case mfmailcomposeresultcancelled: nslog(@"result: canceled"); break; case mfmailcomposeresultsaved: nslog(@"result: saved"); break; case mfmailcomposeresultsent: nslog(@"result: sent"); break; case mfmailcomposeresultfailed: nslog(@"result: failed"); break; default: nslog(@"result: not sent"); break; } [self dismissviewcontrolleranimated:yes completion:nil]; } @end make sure add together messageui.framework. next output.
ios iphone
Comments
Post a Comment