Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 위치 정보 테스트 #423 #426

Merged
merged 3 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NADA-iOS-forRelease/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!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>&quot;사용자의 위치를 받아오려고 합니다.&quot;</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>&quot;사용자의 위치를 받아오려고 합니다.&quot;</string>
<key>CFBundleDevelopmentRegion</key>
<string>ko_KR</string>
<key>CFBundleDisplayName</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Yi Joon Choi on 2021/12/21.
//

import CoreLocation
import UIKit
import Photos

Expand All @@ -18,6 +19,10 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController {
public var isShareable = false
public var cardDataModel: Card?
public var isActivate: Bool?
var locationManager = CLLocationManager()

private var latitude: CLLocationDegrees = 0
private var longitude: CLLocationDegrees = 0

private let cardBackgroundView: UIView = {
let view = UIView()
Expand Down Expand Up @@ -126,6 +131,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
setLocationManager()
}

// MARK: - @Functions
Expand Down Expand Up @@ -161,6 +167,22 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController {

lottieImage.isHidden = isActivate ? false : true
_ = isActivate ? lottieImage.play() : lottieImage.stop()

// TODO: 여기서 스위치 키면 위치정보 받아오기, 끄면 위치 정보 노출하지 않기
if isActivate {
//TODO: 여기서 활성화된 명함 정보/위치정보 API로 쏴주기
locationManager.startUpdatingLocation()
latitude = locationManager.location?.coordinate.latitude ?? 0
longitude = locationManager.location?.coordinate.longitude ?? 0

print("✅ activated")
print("✅ latitude: ", latitude)
print("✅ longitude: ", longitude)

} else {
// TODO: 여기서 비활성화된 명함 정보/위치정보 API로 쏴주기

}
}

private func setupLayout() {
Expand Down Expand Up @@ -340,6 +362,20 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController {
return backImage
}

private func setLocationManager() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()

if CLLocationManager.locationServicesEnabled() {
print("location on")
locationManager.startUpdatingLocation()
print(locationManager.location?.coordinate)
} else {
print("location off")
}
}

// MARK: - @objc Methods

@objc
Expand All @@ -366,3 +402,20 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController {
setCardActivationUI(with: sender.isOn)
}
}

extension CardShareBottomSheetViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("Location Here")
if let location = locations.first {
print("✅ 위도: ", location.coordinate.latitude)
print("✅ 경도: ", location.coordinate.longitude)

latitude = location.coordinate.latitude
longitude = location.coordinate.longitude
}
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
}
}