【问题标题】:how to mail forget password in iphoneiphone忘记密码怎么邮寄
【发布时间】:2012-11-26 08:22:45
【问题描述】:

我正在开发一个应用程序,我想知道如何在 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。

【问题讨论】:

    标签: iphone objective-c


    【解决方案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 web-service 发送电子邮件

    希望对你有帮助……

    【讨论】:

    • 你能告诉我在哪里添加上面的代码很简单,我在(ibaction)forgetpassword方法中添加了
    • 你想在用户点击AlertView的ok按钮时发送邮件吗??
    • @raza 只需删除 alertview 并将上述代码添加到您的忘记密码方法中
    • @raza 但是通过 MFMailComposeViewController 发送的电子邮件将被用户看到,因此没有发送电子邮件的意义。用户可以阅读正在发送的电子邮件,因此使用较少的方法。您可以使用 SKPSMTPMessage / 一些执行此任务的网络服务来使您的密码更安全
    猜你喜欢
    • 2014-01-31
    • 2017-04-26
    • 2020-09-23
    • 2012-02-13
    • 1970-01-01
    • 2012-07-25
    • 2016-08-31
    • 2016-04-26
    • 2012-12-20
    相关资源
    最近更新 更多