有什么方法可以在 iPhone 设置中创建我的个人电子邮件帐户吗?
我正在制作一个发送邮件的应用程序,并希望选择我在 iPhone 上拥有的电子邮件帐户之一进行发送,然后选择我的议程的目标。
谢谢
最佳答案
我不太确定您要做什么,但 iOS 提供了多种显示电子邮件撰写 View Controller 的方法,以及访问用户保存在他/她的 iDevice 上的联系人的方法。
要显示邮件撰写 View ,请在项目中创建一个指向 MessageUI.framework
的弱链接(由于 MessageUI.framework
不可用,因此最好使用弱链接)在非常旧的 iOS 版本上),然后执行如下操作:
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil) {
// MessageUI Library is available. Presenting modal mail composer view.
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"This is the subject of the email"];
[mailViewController setMessageBody:@"This is the body of the email." isHTML:NO];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
} else {
// MessageUI Library not available. Opening mail.app using a URL scheme.
// Note that this URL scheme only works on iOS3 and below, and seems to only accept a
// limited number of characters. For this reason, we only attach the URL.
NSString *mailBody = @"This is the body of the email."
NSString *mailSchemeURL = [NSString stringWithFormat:@"mailto:?body=%@", mailBody];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[mailSchemeURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}
如果您想访问 iDevice 上的联系人,请将 AddressBook.framework
链接到您的项目中。您可以按照 Apple's programming guide 中的说明访问设备上的值。 .例如,您可以获取所有联系人的数组,如下所示:
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *contacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
我希望您可以通过使用上述组合来实例化具有特定联系人的邮件撰写 View 。希望这对您有所帮助!
关于objective-c - 从 iPhone 设置获取邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8970695/