为了节省用户发送电子邮件的时间,用户将电子邮件地址保存在首选项页面中,该页面应在撰写电子邮件时预先填写收件人。(或者这就是我想要做的)这是我卡住的地方,我如何将我保存的字符串用于对象以预先填充收件人。
目前该字符串未预先填写收件人
保存在首选项页面中:
NSString *savecontents = _emailAddress.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savecontents forKey:@"saveEmail"];
[defaults synchronize];
在邮件视图演示文稿中阅读此处
- (IBAction)email:(id)sender {
NSString *savedValue = [[NSUserDefaults standardUserDefaults] <---------- saved email string
stringForKey:@"saveEmail"];
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:savedValue]; <------- trying to get string here
[mail setToRecipients:toRecipients];
[mail setSubject:@"subject"];
NSString *emailBody = [NSString stringWithFormat: @"text here"] ;
[mail setMessageBody:emailBody isHTML:YES];
mail.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mail animated:YES];
}
到目前为止尝试过:
NSArray *toRecipients = [NSString stringWithFormat:savedValue];
[mail setToRecipients:toRecipients];
和
NSArray *toRecipients = [NSString stringWithFormat:@"%@",savedValue];
[mail setToRecipients:toRecipients];
和
谷歌、SO 和敲桌子的拳头