Skip to content

Commit f16161a

Browse files
committed
Added location to kluster and fixed issue when tapping a kluster cell
1 parent 4e0ff61 commit f16161a

File tree

10 files changed

+97
-63
lines changed

10 files changed

+97
-63
lines changed

Cluster.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@
858858
CLANG_ENABLE_MODULES = YES;
859859
ENABLE_BITCODE = NO;
860860
INFOPLIST_FILE = Cluster/Info.plist;
861+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
861862
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
862863
PRODUCT_BUNDLE_IDENTIFIER = "io.ImagineME.$(PRODUCT_NAME:rfc1034identifier)";
863864
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -874,6 +875,7 @@
874875
CLANG_ENABLE_MODULES = YES;
875876
ENABLE_BITCODE = NO;
876877
INFOPLIST_FILE = Cluster/Info.plist;
878+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
877879
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
878880
PRODUCT_BUNDLE_IDENTIFIER = "io.ImagineME.$(PRODUCT_NAME:rfc1034identifier)";
879881
PRODUCT_NAME = "$(TARGET_NAME)";

Cluster.xcworkspace/xcuserdata/mafellows.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,5 @@
1919
landmarkType = "5">
2020
</BreakpointContent>
2121
</BreakpointProxy>
22-
<BreakpointProxy
23-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
24-
<BreakpointContent
25-
shouldBeEnabled = "Yes"
26-
ignoreCount = "0"
27-
continueAfterRunningActions = "No"
28-
filePath = "Cluster/NewKlusterViewController.swift"
29-
timestampString = "478030203.827531"
30-
startingColumnNumber = "9223372036854775807"
31-
endingColumnNumber = "9223372036854775807"
32-
startingLineNumber = "172"
33-
endingLineNumber = "172"
34-
landmarkName = "createNewKlusterButtonClicked(_:)"
35-
landmarkType = "5">
36-
</BreakpointContent>
37-
</BreakpointProxy>
38-
<BreakpointProxy
39-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
40-
<BreakpointContent
41-
shouldBeEnabled = "Yes"
42-
ignoreCount = "0"
43-
continueAfterRunningActions = "No"
44-
filePath = "Cluster/MessagesTableViewController.swift"
45-
timestampString = "478057278.376261"
46-
startingColumnNumber = "9223372036854775807"
47-
endingColumnNumber = "9223372036854775807"
48-
startingLineNumber = "84"
49-
endingLineNumber = "84"
50-
landmarkName = "fetchMessages()"
51-
landmarkType = "5">
52-
</BreakpointContent>
53-
</BreakpointProxy>
5422
</Breakpoints>
5523
</Bucket>

Cluster/Base.lproj/Main.storyboard

Lines changed: 17 additions & 17 deletions
Large diffs are not rendered by default.

Cluster/HomeViewController.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ class HomeViewController: UIViewController {
1818
@IBOutlet weak var currentUserProfileImageButton:UIButton!
1919
@IBOutlet weak var currentUserFullNameButton:UIButton!
2020
@IBOutlet weak var profileAvatar: PFImageView!
21+
@IBOutlet var createKlusterButton: UIButton!
2122

2223
//MARK: - UICollectionViewDataSource
2324
private var klusters = [PFObject]()
25+
var locationManager = CLLocationManager()
2426

2527
//MARK: - Change Status Bar to White
2628
override func preferredStatusBarStyle() -> UIStatusBarStyle {
@@ -30,6 +32,8 @@ class HomeViewController: UIViewController {
3032
override func viewDidLoad() {
3133
super.viewDidLoad()
3234

35+
self.locationManager.delegate = self
36+
3337
// Update the user profile information
3438
let user = PFUser.currentUser()
3539
self.profileAvatar.file = user?.objectForKey("avatarThumbnail") as? PFFile
@@ -52,6 +56,16 @@ class HomeViewController: UIViewController {
5256
super.viewWillAppear(true)
5357

5458
self.fetchKlusters()
59+
60+
let authorizationStatus = CLLocationManager.authorizationStatus()
61+
let locationAuthorized = authorizationStatus == .AuthorizedWhenInUse
62+
self.createKlusterButton.enabled = locationAuthorized
63+
if (locationAuthorized) {
64+
self.locationManager.startUpdatingLocation()
65+
} else {
66+
// let's request location authorization
67+
self.locationManager.requestWhenInUseAuthorization()
68+
}
5569
}
5670

5771
private func showLogin() {
@@ -100,6 +114,7 @@ extension HomeViewController : UICollectionViewDataSource
100114
cell.joinKlusterButton.addTarget(self, action: "joinKluster:", forControlEvents: UIControlEvents.TouchUpInside)
101115

102116
// Moved the PFImageView loading out of the cell
117+
cell.featuredImageView.tag = indexPath.row
103118
cell.featuredImageView.image = nil
104119
cell.featuredImageView.file = k.featuredImageFile
105120
cell.featuredImageView.loadInBackground { (image, error) -> Void in
@@ -142,6 +157,16 @@ extension HomeViewController : UICollectionViewDataSource
142157
}
143158
}
144159

160+
extension HomeViewController : CLLocationManagerDelegate {
161+
162+
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
163+
if (status == .AuthorizedWhenInUse) {
164+
self.createKlusterButton.enabled = true
165+
self.locationManager.startUpdatingLocation()
166+
}
167+
}
168+
}
169+
145170
//MARK: - Scrolling Experience
146171
extension HomeViewController : UIScrollViewDelegate
147172
{

Cluster/ImagePickerSheet/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>NSLocationUsageDescription</key>
6+
<string>We need your location to show you nearby Klusters.</string>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>en</string>
79
<key>CFBundleExecutable</key>

Cluster/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>NSLocationWhenInUseUsageDescription</key>
6+
<string>We need your location to show you nearby Klusters. </string>
57
<key>CFBundleURLTypes</key>
68
<array>
79
<dict>

Cluster/KlusterDataSource.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import Foundation
1010

1111
class KlusterDataSource: NSObject {
12-
class func createKlusterWithParams(params: Dictionary<String, String>, completion:PFIdResultBlock) -> Void
12+
class func createKlusterWithParams(params: [NSObject : AnyObject]?, completion:PFIdResultBlock) -> Void
1313
{
14-
PFCloud.callFunctionInBackground("createKluster", withParameters: params) {
15-
(object, error) in
14+
PFCloud.callFunctionInBackground("createKluster", withParameters: params) { (object, error) -> Void in
1615
completion(object, error)
1716
}
1817
}

Cluster/LocationSelectViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import Foundation
1010
import MapKit
11-
11+
import CoreLocation
1212

1313
class LocationSelectViewController: UIViewController {
1414

1515
@IBOutlet var mapView: MKMapView!
1616

17-
public var completion: (String? -> ())?
17+
public var completion: (Int? -> ())?
1818

1919
override func viewDidLoad() {
2020
super.viewDidLoad()

Cluster/Map.storyboard

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="WED-3T-02Y">
33
<dependencies>
44
<deployment identifier="iOS"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
@@ -48,7 +48,7 @@
4848
</viewController>
4949
<placeholder placeholderIdentifier="IBFirstResponder" id="XhS-tg-gzm" userLabel="First Responder" sceneMemberID="firstResponder"/>
5050
</objects>
51-
<point key="canvasLocation" x="1453" y="637"/>
51+
<point key="canvasLocation" x="1453" y="580"/>
5252
</scene>
5353
<!--Navigation Controller-->
5454
<scene sceneID="1hH-AD-rdb">
@@ -64,7 +64,7 @@
6464
</navigationController>
6565
<placeholder placeholderIdentifier="IBFirstResponder" id="qqu-Dc-kvm" userLabel="First Responder" sceneMemberID="firstResponder"/>
6666
</objects>
67-
<point key="canvasLocation" x="754" y="727"/>
67+
<point key="canvasLocation" x="599" y="465"/>
6868
</scene>
6969
</scenes>
7070
</document>

Cluster/NewKlusterViewController.swift

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class NewKlusterViewController: UIViewController, UIImagePickerControllerDelegat
2727

2828
@IBOutlet var hideKeyboardInputAccessoryView: UIView!
2929
private var featuredImage: UIImage!
30-
30+
private var klusterLocation: PFGeoPoint!
31+
3132
@IBOutlet weak var chooseLocationPressed: DesignableButton!
3233

3334
override func preferredStatusBarStyle() -> UIStatusBarStyle {
@@ -86,10 +87,43 @@ class NewKlusterViewController: UIViewController, UIImagePickerControllerDelegat
8687
}
8788

8889
@IBAction func chooseLocationButtonClicked(sender: DesignableButton) {
89-
let storyboard = UIStoryboard.init(name: "Map", bundle: nil)
90-
let mapController = storyboard.instantiateInitialViewController()
91-
self.presentViewController(mapController!, animated: true, completion: nil)
90+
let actionSheet = UIAlertController.init(title: "Select Kluster Location", message: nil, preferredStyle: .ActionSheet)
91+
92+
let currentLocationAction = UIAlertAction.init(title: "Current Location", style: .Default) { (action) -> Void in
93+
PFGeoPoint.geoPointForCurrentLocationInBackground({ (geoPoint, error) -> Void in
94+
if (error != nil) {
95+
print("Error grabbing current location")
96+
let alert = UIAlertController.init(title: "Error", message: "Unable to get your current location. Please try again.", preferredStyle: .Alert)
97+
let ok = UIAlertAction.init(title: "Okay", style: .Default, handler: nil)
98+
alert.addAction(ok)
99+
self.presentViewController(alert, animated: true, completion: nil)
100+
} else {
101+
self.klusterLocation = geoPoint
102+
}
103+
})
104+
}
105+
106+
actionSheet.addAction(currentLocationAction)
107+
108+
let pickLocation = UIAlertAction.init(title: "Pick A Location", style: .Default) { (action) -> Void in
109+
self.presentViewController(actionSheet, animated: true, completion: nil)
110+
let storyboard = UIStoryboard.init(name: "Map", bundle: nil)
111+
let mapController = storyboard.instantiateInitialViewController() as! UINavigationController
112+
// let locationController = mapController.childViewControllers.first as! LocationSelectViewController
113+
self.presentViewController(mapController, animated: true, completion: nil)
114+
}
115+
116+
actionSheet.addAction(pickLocation)
117+
118+
let cancelAction = UIAlertAction.init(title: "Cancel", style: .Cancel) { (action) -> Void in
119+
actionSheet.dismissViewControllerAnimated(true, completion: nil)
120+
}
121+
122+
actionSheet.addAction(cancelAction)
123+
124+
self.presentViewController(actionSheet, animated: true, completion: nil)
92125
}
126+
93127
@IBAction func selectFeaturedImageButtonClicked(sender: DesignableButton) {
94128

95129
let authorization = PHPhotoLibrary.authorizationStatus()
@@ -168,9 +202,11 @@ class NewKlusterViewController: UIViewController, UIImagePickerControllerDelegat
168202
let params = ["title": title!,
169203
"summary": summary!,
170204
"plans": plans!,
171-
"photo": base64String!] as Dictionary<String, String>
205+
"latitude": self.klusterLocation.latitude,
206+
"longitude": self.klusterLocation.longitude,
207+
"photo": base64String!]
172208

173-
KlusterDataSource.createKlusterWithParams(params, completion: { (object, error) -> Void in
209+
KlusterDataSource.createKlusterWithParams(params as [NSObject : AnyObject], completion: { (object, error) -> Void in
174210
if error != nil {
175211
hud.removeFromSuperview()
176212
} else {

0 commit comments

Comments
 (0)