我一直在试图找到一个解决方案,但没有运气:/我想调用我的firebase数据字符串,并将它们用作UIAlertView中的“标题”和“消息”。我正在使用此UIAlertView作为地理围栏信息。如果我只是将UIAlertView设置为输入消息的基本窗口,但是我需要它调用他们为其他用户阅读的消息,则地理围栏工作正常。到目前为止,这个设置只弹出“确定”按钮,没有别的东西进入一个区域。Swift Firebase UIAlertView与Firebase数据字符串
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
showAlert(withTitle: name, message: message)
//showAlert(withTitle: "Enter \(region.identifier)", message: "Geofence Message")
print(state)
print("region :\(region.identifier)")
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
showAlert()
//showAlert(withTitle: "Enter \(region.identifier)", message: "Geofence Message")
print("DID ENTER REGION")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
//showAlert(withTitle: "Exit \(region.identifier)", message: "Message Exit")
//TODO: stop local sequence
print("DID EXIT REGION")
}
func showAlert(withTitle title: String?, message: String?) {
FIRDatabase.database().reference().child("Businesses").observeSingleEvent(of: .value, with: { snapshot in
if let dictionary = snapshot.value as? [String: AnyObject] {
self.name = dictionary["businessName"] as? String
self.message = dictionary["geofenceMessage"] as? String
}
let alert = UIAlertController(title: self.name, message: self.message, preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .cancel, handler: nil)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
})
}
更多信息
// Populate Map With Firebase Businesses
func loadPlaces(){
if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) {
FIRDatabase.database().reference().child("Businesses").observe(.value, with: { snapshot in
self.locationData = snapshot.value as? NSDictionary
if let data = self.locationData{
for (key,obj) in data{
let value = obj as? NSDictionary
let locationValue = value as! [String: Any]
let lat = Double(locationValue["businessLatitude"] as! String)
let long = Double(locationValue["businessLongitude"] as! String)
let businessTitle = String(locationValue["businessName"] as! String)
let center = CLLocationCoordinate2D(latitude: lat!, longitude: long!)
let radius = CLLocationDistance(500.0)
let geoRegion = CLCircularRegion(center: center, radius: radius, identifier: businessTitle!)
self.geofences.append(geoRegion)
self.locationManager.startMonitoring(for: geoRegion)
let overlay = MKCircle(center: center, radius: radius)
self.mapView.add(overlay)
geoRegion.notifyOnEntry = true
geoRegion.notifyOnExit = true
let annotation = MKPointAnnotation()
annotation.coordinate = geoRegion.center
annotation.title = businessTitle
self.mapView.addAnnotation(annotation)
self.nameKeyDict[(value?.value(forKey: "businessName") as? String)!] = key as? String
}
}
})
} else {
print("No Bueno")
}
}
火力地堡数据结构
只因为你不明白答案,不要让他们“疯狂”。这对你花时间去帮助你的人来说会很谦虚。 – matiastofteby