swift, objective-C

swift 2.0 -- parse 로그인 따라하기

자유프로그램 2015. 9. 22. 14:52
반응형

swift 2.0 -- parse 로그인 따라하기


환경 : swift 2.0, xcode 7.0


참고 :  https://www.youtube.com/watch?v=XIJLIywoSoA

          http://stackoverflow.com/a/32480189

         https://www.youtube.com/watch?v=7sL47vpWTMU  -- 추가 동영상



유투브 동상상 보면서 parse 로그인 따라하기 !!!





** 사전 준비사항 

    ;  parse.com  에 가입하기


** parse libarary 설치시 변경사항 

    -- dylib 없음.  --> tbd 파일로 대체하면 됨.  (http://stackoverflow.com/a/32480189)




** 스토리보드 설정


** 코드


//
// ViewController.swift
// ParseLogin
//
import UIKit
import Parse
class ViewController: UIViewController {
@IBOutlet weak var UsernameTextField: UITextField!
@IBOutlet weak var PasswordTF: UITextField!
@IBOutlet weak var EmailTF: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func LogInBtnAction(sender: AnyObject) {
LogIn()
}
func LogIn() {
let user = PFUser()
user.username = UsernameTextField.text
user.password = PasswordTF.text
PFUser.logInWithUsernameInBackground(user.username!, password: user.password!) { (User:PFUser?, Error:NSError?) -> Void in
if Error == nil {
print("... login success")
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let Storyboard = UIStoryboard(name: "Main", bundle: nil)
let MainVC: UIViewController = Storyboard.instantiateViewControllerWithIdentifier("MainVC")
let mylabel = MainVC.view.viewWithTag(1) as? UILabel
mylabel!.text = "로그인 성공!"
self.presentViewController(MainVC, animated: true, completion: nil)
})
}
else {
print("... login fail")
// NSLog("Wrong!!!")
}
}
}
@IBAction func SignUpBtnAction(sender: AnyObject) {
SignUp()
}
func SignUp() {
let user = PFUser()
user.username = UsernameTextField.text
user.password = PasswordTF.text
user.email = EmailTF.text
user.signUpInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
if error == nil {
// Hooray! Let them use the app now.
print("... signup success")
} else {
// Examine the error object and inform the user.
print("... signup fail")
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}










반응형