Ios 如何在Xcode中在应用程序内部发送电子邮件?
我是xcode新手,想知道如何在应用程序中发送电子邮件!下面是我的代码,但我一直收到错误“没有可见的@interface for'jakem'声明选择器'presentViewControllerAnimated:'”。我的代码完全错了吗?还是我忘了声明选择器,如何声明选择器?我在互联网上搜索了至少一个小时,但什么都没用。有人请帮帮我Ios 如何在Xcode中在应用程序内部发送电子邮件?,ios,email,send,Ios,Email,Send,我是xcode新手,想知道如何在应用程序中发送电子邮件!下面是我的代码,但我一直收到错误“没有可见的@interface for'jakem'声明选择器'presentViewControllerAnimated:'”。我的代码完全错了吗?还是我忘了声明选择器,如何声明选择器?我在互联网上搜索了至少一个小时,但什么都没用。有人请帮帮我 -(IBAction)sendEmail{ MFMailComposeViewController *composer = [[MFMailCo
-(IBAction)sendEmail{
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:@"FrankMurphy.CEO@RomansXIII.com", nil]];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:composer animated:YES];
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if(error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" message:[NSString stringWithFormat:@"error %@", [error description]] delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
[alert show];
[self dismissViewControllerAnimated:YES];
}
else {
[self dismissViewControllerAnimated:YES];
}
}
检查您是否为MFMAILCOMPOSEVIEWCONTROLLERGATE。 你这样做吗
@interface YouClassName : UIViewController <MFMailComposeViewControllerDelegate>
@end
@接口YouClassName:UIViewController
@结束
我认为您使用了错误的方法。试一试
[self presentViewController:(UIViewController *) animated:(BOOL) completion:(void)completion];
而不是:
[self presentViewController:composer animated:YES];
我在Sendgrid工作。我们有一个Objective-c库,可以让您从应用程序内部快速发送电子邮件。您可以使用cocoapod在项目中快速安装库 然后,从您的(IBAction)发送电子邮件将如下所示:
-(IBAction)sendEmail{
sendgrid *msg = [sendgrid user:@"username" andPass:@"password"];
msg.to = @"FrankMurphy.CEO@RomansXIII.com";
msg.from = @"me@bar.com";
msg.text = @"hello world";
msg.html = @"<h1>hello world!</h1>";
[msg sendWithWeb];
}
-(iAction)发送电子邮件{
sendgrid*msg=[sendgrid用户:@“用户名”和密码];
msg.to=@“弗兰克墨菲。CEO@RomansXIII.com";
msg.from=@”me@bar.com";
msg.text=@“你好,世界”;
msg.html=@“你好,世界!”;
[msg sendWithWeb];
}
在.h头文件中
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface SimpleEmailViewController : UIViewController <MFMailComposeViewControllerDelegate> // Add the delegate
- (IBAction)showEmail:(id)sender;
@end
谢谢你的回复!是的,我在头文件中这样做了
- (IBAction)showEmail:(id)sender {
// Email Subject
NSString *emailTitle = @"Test Email";
// Email Content
NSString *messageBody = @"iOS programming is so fun!";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"info@finetechnosoft.in"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}