gpt4 book ai didi

ios - 如何在 Xcode 的应用程序内发送电子邮件?

转载 作者:可可西里 更新时间:2023-11-01 04:35:42 25 4
gpt4 key购买 nike

我是 xcode 的新手,想知道如何在应用程序中发送电子邮件!我的代码在下面,但我不断收到错误消息“'jakem' 的可见@interface 声明选择器'presentViewControllerAnimated:'”。我的代码完全错误吗?或者我只是忘记声明选择器,我该如何声明选择器?我已经在互联网上研究了至少一个小时,但没有任何效果。有人请帮助我!

    -(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];
}
}

最佳答案

在 .h 头文件中....

 #import <UIKit/UIKit.h>


#import <MessageUI/MessageUI.h>



@interface SimpleEmailViewController : UIViewController <MFMailComposeViewControllerDelegate> // Add the delegate
- (IBAction)showEmail:(id)sender;



@end

在.m实现文件中......

- (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];
}

关于ios - 如何在 Xcode 的应用程序内发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17301000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com