解密码重置功能

Har*_*man -2 ios parse-platform swift xcode6.1

我试图在我的ios应用程序中使用密码重置进行解析,我似乎无法在swift中找到关于如何将其实现为按钮操作但没有找到任何内容的最佳方法的任何教程.

谁知道一个好看的地方?这就是我到目前为止所拥有的

@IBAction func resetPassword(sender: AnyObject) {

    [PFUser requestPasswordResetForEmailInBackground:
        self.loginEmail.text
        block:^(BOOL succeeded, NSError *error)
        {
        [APP.hud hide:YES];
        if (!succeeded)
        {
        NSString *msg = @"Could not connect. Try again later.";
        [UIAlertView ok:msg];
        return;
        }

        [UIAlertView minimalistMessageFor:3.0
        title:nil
        message:@"Your password has been sent to your email address."
        then:^{ }];
        [self begin];
        }];

}
Run Code Online (Sandbox Code Playgroud)

我在PFUser线上的这个容器文字错误中得到一个Expected表达式.

Hen*_*ijn 5

我在我正在使用的应用程序中使用以下内容,弹出警报框以输入您的电子邮件并在新警报框中确认结果:

@IBAction func resetPasswordPressed(sender: AnyObject) {

    let titlePrompt = UIAlertController(title: "Reset password",
        message: "Enter the email you registered with:",
        preferredStyle: .Alert)

    var titleTextField: UITextField?
    titlePrompt.addTextFieldWithConfigurationHandler { (textField) -> Void in
        titleTextField = textField
        textField.placeholder = "Email"
    }

    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)

    titlePrompt.addAction(cancelAction)

    titlePrompt.addAction(UIAlertAction(title: "Reset", style: .Destructive, handler: { (action) -> Void in
            if let textField = titleTextField {
                self.resetPassword(textField.text)
            }
    }))

    self.presentViewController(titlePrompt, animated: true, completion: nil)
}

func resetPassword(email : String){

    // convert the email string to lower case
    let emailToLowerCase = email.lowercaseString
    // remove any whitespaces before and after the email address
    let emailClean = emailToLowerCase.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())

    PFUser.requestPasswordResetForEmailInBackground(emailClean) { (success, error) -> Void in
        if (error == nil) {
            let success = UIAlertController(title: "Success", message: "Success! Check your email!", preferredStyle: .Alert)
            let okButton = UIAlertAction(title: "OK", style: .Default, handler: nil)
            success.addAction(okButton)
            self.presentViewController(success, animated: false, completion: nil)

        }else {
            let errormessage = error!.userInfo!["error"] as! NSString
            let error = UIAlertController(title: "Cannot complete request", message: errormessage as String, preferredStyle: .Alert)
            let okButton = UIAlertAction(title: "OK", style: .Default, handler: nil)
            error.addAction(okButton)
            self.presentViewController(error, animated: false, completion: nil)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用与重置方法显示的方式类似的方式将电子邮件用户注册表转换为小写之前也很聪明.

如果要放入活动指示器,以便用户看到应用程序在操作之间忙,请创建以下两种方法,并在if/else之前或之后的Reset操作和Restore()中调用Pause()在resetPassword方法中.还包括以下类变量: var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()

func pause(){
    activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
    activityIndicator.center = self.view.center
    activityIndicator.hidesWhenStopped = true
    activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
    view.addSubview(activityIndicator)
    activityIndicator.startAnimating()
    UIApplication.sharedApplication().beginIgnoringInteractionEvents()
}

func restore(){
    activityIndicator.stopAnimating()
    UIApplication.sharedApplication().endIgnoringInteractionEvents()
}
Run Code Online (Sandbox Code Playgroud)