Add location

This commit is contained in:
kevinzhow
2015-04-02 07:07:19 +08:00
parent 9fe4e3f169
commit 9bdaf0140c
5 changed files with 75 additions and 3 deletions
+4
View File
@@ -14,6 +14,7 @@
0A3E60601ACCA9C0003DC853 /* String+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A3E605F1ACCA9C0003DC853 /* String+Yep.swift */; };
0A3E60621ACCAB50003DC853 /* NSDate+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A3E60611ACCAB50003DC853 /* NSDate+Extension.swift */; };
0A3E60651ACCAC1D003DC853 /* NSDateTimeAgo.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 0A3E60641ACCAC1D003DC853 /* NSDateTimeAgo.bundle */; };
0A3E60671ACCAECE003DC853 /* YepLocationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A3E60661ACCAECE003DC853 /* YepLocationService.swift */; };
0A5D83941AC5D3C8000045BF /* YepTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D83931AC5D3C8000045BF /* YepTabBarController.swift */; };
0A5D83991AC5D91E000045BF /* ContactsSearchTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D83981AC5D91E000045BF /* ContactsSearchTableViewController.swift */; };
0A6F46FD1ACBBF2D000CCD6F /* Waver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6F46FC1ACBBF2D000CCD6F /* Waver.swift */; };
@@ -114,6 +115,7 @@
0A3E605F1ACCA9C0003DC853 /* String+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "String+Yep.swift"; path = "Extensions/String+Yep.swift"; sourceTree = "<group>"; };
0A3E60611ACCAB50003DC853 /* NSDate+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSDate+Extension.swift"; sourceTree = "<group>"; };
0A3E60641ACCAC1D003DC853 /* NSDateTimeAgo.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = NSDateTimeAgo.bundle; sourceTree = "<group>"; };
0A3E60661ACCAECE003DC853 /* YepLocationService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepLocationService.swift; path = Services/YepLocationService.swift; sourceTree = "<group>"; };
0A5D83931AC5D3C8000045BF /* YepTabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepTabBarController.swift; path = ViewControllers/TabBar/YepTabBarController.swift; sourceTree = "<group>"; };
0A5D83981AC5D91E000045BF /* ContactsSearchTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactsSearchTableViewController.swift; path = ViewControllers/Contacts/Search/ContactsSearchTableViewController.swift; sourceTree = "<group>"; };
0A6F46FC1ACBBF2D000CCD6F /* Waver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Waver.swift; sourceTree = "<group>"; };
@@ -500,6 +502,7 @@
5076C5691AC46B9F00B22952 /* FayeService.swift */,
0A944C241AC8BB2F00037A06 /* YepStorageService.swift */,
0A271FD61ACA055400822DFC /* YepAudioService.swift */,
0A3E60661ACCAECE003DC853 /* YepLocationService.swift */,
);
name = Services;
sourceTree = "<group>";
@@ -926,6 +929,7 @@
502AE5291AB81076005BD199 /* YepService.swift in Sources */,
502AE51E1AB712D2005BD199 /* RegisterPickNameViewController.swift in Sources */,
50E114F91ABC137A00F13000 /* YepServiceSync.swift in Sources */,
0A3E60671ACCAECE003DC853 /* YepLocationService.swift in Sources */,
5023DE2A1AB685BA00B3EE96 /* ContactsViewController.swift in Sources */,
50CDBE491ACBAD3200459CE0 /* ChatLeftImageCell.swift in Sources */,
5033159C1AC101C80008A209 /* ChatRightTextCell.swift in Sources */,
+2
View File
@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Find pepole around you</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
+55
View File
@@ -0,0 +1,55 @@
//
// YepLocationService.swift
// Yep
//
// Created by kevinzhow on 15/4/2.
// Copyright (c) 2015 Catch Inc. All rights reserved.
//
import CoreLocation
class YepLocationService: NSObject, CLLocationManagerDelegate {
static let sharedManager = YepLocationService()
var locationManager:CLLocationManager = CLLocationManager()
var currentLocation:CLLocation?
var address:String?
var geocoder = CLGeocoder()
override init() {
super.init()
locationManager.delegate = self
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.pausesLocationUpdatesAutomatically = true
locationManager.headingFilter = kCLHeadingFilterNone
locationManager.requestWhenInUseAuthorization()
println("Prepare Location")
if (CLLocationManager.locationServicesEnabled()){
println("Update Location")
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
geocoder.reverseGeocodeLocation(newLocation, completionHandler: { (placemarks, error) in
if (error != nil) {println("reverse geodcode fail: \(error.localizedDescription)")}
if let pm = placemarks as? [CLPlacemark] {
if pm.count > 0 {
var placemark = pm.first
self.address = placemark?.locality
NSNotificationCenter.defaultCenter().postNotificationName("YepLocationUpdated", object: self.address)
}
}
})
}
}
@@ -38,6 +38,17 @@ class ProfileHeaderCell: UICollectionViewCell {
}
}
}
YepLocationService.sharedManager
NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateAddress", name: "YepLocationUpdated", object: nil)
}
func updateAddress() {
println("Location YepLocationUpdated")
self.locationLabel.text = YepLocationService.sharedManager.address
}
func tryChangeAvatar() {
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7525" systemVersion="14C1510" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7528.3" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7516"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7518.3"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -28,7 +28,7 @@
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="CandyStar" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="O8h-bQ-ZK8" userLabel="Location Label">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="O8h-bQ-ZK8" userLabel="Location Label">
<rect key="frame" x="320" y="219" width="53" height="15"/>
<fontDescription key="fontDescription" type="system" weight="thin" pointSize="12"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>