-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignUpViewController.swift
86 lines (55 loc) · 2.6 KB
/
SignUpViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// SignUpViewController.swift
// MatchMaker
//
// Created by Aditya Vikram Godawat on 01/02/16.
// Copyright © 2016 Wow Labz. All rights reserved.
//
import UIKit
import Parse
import FBSDKCoreKit
class SignUpViewController: UIViewController {
@IBOutlet var userImage: UIImageView!
@IBOutlet var interestedInWomen: UISwitch!
@IBAction func signUp(sender: AnyObject) {
PFUser.currentUser()?["interestedInWomen"] = interestedInWomen.on
do { try PFUser.currentUser()?.save()
} catch {
}
self.performSegueWithIdentifier("loggingIn", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender,email"])
graphRequest.startWithCompletionHandler { (connection, result, error) -> Void in
if error != nil {
print(error)
} else {
if let result = result {
PFUser.currentUser()?["gender"] = result["gender"]
PFUser.currentUser()?["name"] = result["name"]
PFUser.currentUser()?["email"] = result["email"]
do { try PFUser.currentUser()?.save()
} catch {
}
let userId = result["id"] as! String
let facebookProfilePictureURL = "https:/graph.facebook.com/" + userId + "/picture?type=large"
if let fbpicURL = NSURL(string: facebookProfilePictureURL) {
if let data = NSData(contentsOfURL: fbpicURL) {
self.userImage.image = UIImage(data: data)
let imageFile: PFFile = PFFile(data: data)!
PFUser.currentUser()?["image"] = imageFile
do { try PFUser.currentUser()?.save()
} catch {
}
}
}
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}