1

我正在开发一个应用程序,我想知道如何在 iPhone 中实现忘记密码的情况。

当用户忘记他们的密码时,我的应用程序中有一个按钮,当我点击它UIAlertView打开时,我有一个文本字段,用户必须输入他们的电子邮件地址,密码才能在该邮件 ID 上获取邮件。

我该怎么做,我已经为按钮定义了一个动作,这是代码:

-(IBAction)forgetpassword:(id)sender
{
    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Forget Password" message:@"Please Enter your Email address " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    av.alertViewStyle = UIAlertViewStylePlainTextInput;
    [av textFieldAtIndex:0].delegate = self;
    [av show];
}

但我需要的只是需要我可以使用的代码并将密码邮寄到用户将输入的电子邮件 ID。

4

1 回答 1

1

只需将委托添加MFMessageComposeViewControllerDelegate到 .h 文件,然后在您想发送电子邮件时使用此代码,并MessageUI.framework在项目中添加框架

-(IBAction)forgetpassword:(id)sender
{
     if ([MFMailComposeViewController canSendMail]) 
     {

        MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
        NSString *mailBody = @"your Message";


        [mailComposeViewController setMessageBody:mailBody isHTML:NO];
        mailComposeViewController.mailComposeDelegate = self;
        [self presentViewController:mailComposeViewController animated:YES completion:nil];
    } 
    else 
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"e-Mail Sending Alert"
                                                        message:@"You can't send a mail"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

这个波纹管方法是委托方法MFMessageComposeViewControllerDelegate

#pragma mark - MFMessage Delegate

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    if (result == MFMailComposeResultSent) 
    {
        NSLog(@"\n\n Email Sent");
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

您还可以使用SKPSMTPmessage网络服务发送电子邮件

我希望这可以帮助你...

于 2012-11-26T08:27:28.423 回答