开发者

Why won't the MFMailComposeViewController's Cancel or Send buttons work?

开发者 https://www.devze.com 2022-12-23 22:14 出处:网络
I have a problem... I create a MFMailComposeViewControll开发者_Go百科er and it shows up. However, neither the Send nor the Cancel button work.You have to put on this code in ur application,

I have a problem...

I create a MFMailComposeViewControll开发者_Go百科er and it shows up.

However, neither the Send nor the Cancel button work.


You have to put on this code in ur application,

   - (void)mailComposeController:(MFMailComposeViewController*)controller     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
[self dismissModalViewControllerAnimated:YES];
}

Try this one and it works send and cancel buttons properly.


MFMailComposeViewController *controller=[[MFMailComposeViewController alloc]init];
controller.mailComposeDelegate=self;

[controller setSubject:@"Important Data"];

for html file mail

NSString *path=[[NSBundle mainBundle]pathForResource:@"table" ofType:@"html"];
NSFileHandle *readHandle=[NSFileHandle fileHandleForReadingAtPath:path];
htmlString = [[NSString alloc] initWithData: [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];

NSString *emailBody=[NSString stringWithFormat:@"Product Name         %@ \n Company Name       %@  \n Last Updated Date   %@ \n desired data \n %@  ",lblProductName.text,lblCompanyName.text,lblUpdateDate.text,htmlString];

[controller setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:controller animated:YES];

[controller release];


Today I found Swift 3.0 brings a new function signature to this question. Before this, mailComposeController was never even called, and the mail (although it did send) just stuck there. When I changed to below, it worked.

  public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith: MFMailComposeResult, error: Error?) {

    self.dismiss(animated:true, completion: nil)


}
0

精彩评论

暂无评论...
验证码 换一张
取 消