-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfilePhotoUploadViewController.swift
86 lines (66 loc) · 3.08 KB
/
ProfilePhotoUploadViewController.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
//
// ProfilePhotoUploadViewController.swift
// VenopsMobileApp
//
// Created by Jay Maloney on 2/5/16.
// Copyright © 2016 Jay Maloney. All rights reserved.
//
import UIKit
class ProfilePhotoUploadViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// MARK: OUTLETS
@IBOutlet weak var photoImage: UIImageView!
// MARK: ACTIONS
@IBAction func addPhoto(sender: AnyObject) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
// Selection Alert
let avatarAlert = UIAlertController(title: "Select Photo Location", message: nil, preferredStyle: .ActionSheet)
// Library Picker
if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) {
avatarAlert.addAction(UIAlertAction(title: "Library", style: .Default, handler: { (_) -> Void in
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: true, completion: nil)
}))
}
// Camera
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
avatarAlert.addAction(UIAlertAction(title: "Camera", style: .Default, handler: { (_) -> Void in
imagePicker.sourceType = .Camera
self.presentViewController(imagePicker, animated: true, completion: nil)
}))
}
avatarAlert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.presentViewController(avatarAlert, animated: true, completion: nil)
})
}
@IBAction func skipTapped(sender: AnyObject) {
self.performSegueWithIdentifier("skipPhoto", sender: nil)
}
// MARK: UIImagePickerController Delegate
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker.dismissViewControllerAnimated(true, completion: nil)
if let myImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
self.photoImage.image = myImage
if let userID = UserController.sharedController.currentUser.identifier {
ImageController.saveProfileImage(identifier: userID, image: myImage, completion: { (success) -> Void in
if success {
self.performSegueWithIdentifier("skipPhoto", sender: nil)
}
})
}
ImageController.saveSelectedProfileImage(myImage)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}