2017-12-30 20 views
-2

GeoFire를 사용하여 사용자의 현재 위치를 기반으로 Firebase에서 데이터를 쿼리하고 있습니다. 나는 얻고있다 :Firebase 규칙에 인덱스 추가

불특정 색인 사용. 성능 향상을 위해 보안 규칙을 에 /에서 "g"

콘솔

을 ".indexOn"를 추가하는 것이 좋습니다. 다음은 내 쿼리 코드입니다.

  ref = Database.database().reference() 
      let geoFire = GeoFire(firebaseRef: ref) 

      let center = CLLocation(latitude: (userLocation.coordinate.latitude), longitude: (userLocation.coordinate.longitude)) 

      let circleQuery = geoFire?.query(at: center, withRadius: 1) 

      circleQuery?.observe(.keyEntered, with: { key, location in 

       guard let key = key else { return } 

       geoFire?.getLocationForKey(key, withCallback: { (location, error) in 

        let myAnnotation: MKPointAnnotation = MKPointAnnotation() 
        myAnnotation.coordinate = CLLocationCoordinate2DMake((location?.coordinate.latitude)!, (location?.coordinate.longitude)!); 
        self.currentLocationMapView.addAnnotation(myAnnotation)  
       }) 


       self.ref.child("services").child(key).observeSingleEvent(of: .value, with: { (snapshot) in 

        let value = snapshot.value as? NSDictionary 
        let servicename = value?["name"] as? String ?? "" 
        let address = value?["address"] as? String ?? "" 

        self.nameArray.append(servicename) 
        self.addressArray.append(address) 


        if (self.nameArray.count > 0) { 
         self.customTableView.reloadData();  
        } 

       }) 

      }) 

내 Firebase 규칙 탭에는 다음과 같은 설정이 있습니다.

"rules": { 
    ".read": true, 
     ".write": "auth != null" 
      } 

".indexOn"을 삽입 한 위치와 관계없이 : "g"오류가 발생하여 규칙을 저장할 수 없습니다. 어떤 도움이 필요합니까?

답변

1

documentationexamples입니다.

"rules": { 
    ".read": true, 
    ".write": "auth != null", 
    ".indexOn": ["g"] 
} 
+0

작동하지 않습니다. 여전히 오류가 발생했다고 말합니다. – Kalaichelvan

관련 문제