我一直在試圖找到一個解決方案,但沒有運氣:/我想調用我的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