firebase에서 데이터를 가져와 거리별로 구성하고 사용자가 앱을 중단하지 않기를 바라는 tableview가 있기 때문에 위치 서비스가 활성화 된 경우 코드 실행에 도움이 필요합니다. . 또한 위치 서비스가 활성화 된 경우에만 코드를 실행하려는 UIRefreshControl도 있습니다. 현재 내 설정은 내가 원하는 것을하지 않습니다. 내 전체 ViewDidLoad뿐만 아니라 내 UIRefreshControl 게시 오전. getTableViewData()는 위치 서비스가 사용되는 경우 기반으로 실행하고자하는 코드입니다. 감사.Swift 위치 서비스가 활성화 된 경우에만 코드 실행
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
locationManager.delegate = self
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
locationManager.stopUpdatingLocation()
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
switch(CLLocationManager.authorizationStatus()) {
case .notDetermined, .restricted, .denied:
print("No access")
case .authorizedAlways, .authorizedWhenInUse:
print("Access")
getTableViewData()
}
} else {
print("Location services are not enabled")
}
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to refresh")
refresher.addTarget(self, action: #selector(RegisteredLocations.handleRefresh(refreshControl:)), for: UIControlEvents.valueChanged)
tableView.addSubview(refresher)
}
@objc func handleRefresh(refreshControl: UIRefreshControl) {
self.usersArray.removeAll()
if CLLocationManager.locationServicesEnabled() {
switch(CLLocationManager.authorizationStatus()) {
case .notDetermined, .restricted, .denied:
print("No access")
case .authorizedAlways, .authorizedWhenInUse:
print("Access")
getTableViewData()
}
} else {
print("Location services are not enabled")
}
self.tableView.reloadData()
refreshControl.endRefreshing()
}
어떻게됩니까? 작동하지 않는 것은 무엇입니까? –
액세스를 허용 할 때 "getTableViewData()"를 실행하지 않습니다. –
액세스가 거부 된 경우 "getTableViewData()"를 실행하지 않으려합니다. –