2017-10-31 7 views
0

Firebase Cloud Firestoreで以下のコードを使用してデータを取得します。Firebase Firestore Swiftでドキュメントが使用できない

ボタンプレスはブール値を取得する必要があり、アプリケーションが別のビューコントローラーにナビゲートするいくつかの条件を満たす場合、最初のクリックでうまく動作しますが、戻って同じボタンを押しても結果は表示されませんもう一度フェッチしてください!

db.collection("users").document((Auth.auth().currentUser?.uid)!).getDocument { (snap, error) in 
       if error != nil { 
        print(error.debugDescription) 
       } 
       if snap != nil { 
        let isPosted = snap?.data()["isPosted"] as! Bool 
        let isStroe = snap?.data()["isStore"] as! Bool 
        if !isPosted && !isStroe { 
         print("first post") 
         let useraccountVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "newData") as! UINavigationController 
         self.present(useraccountVC, animated: true, completion: nil) 
        }else if isPosted && isStroe { 
         print("store") 
         let useraccountVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "newData") as! UINavigationController 
         self.present(useraccountVC, animated: true, completion: nil) 
        }else if !isPosted && isStroe{ 
         print("store") 
         let useraccountVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "newData") as! UINavigationController 
         self.present(useraccountVC, animated: true, completion: nil) 
        }else{ 

         print("cant post any more") 
        } 

       } 

      } 

答えて

0

このため価格モデルmakes an explicit provision:リスナーは30分以上切断された場合(例えば、ユーザーがオフラインになった場合、)として読み込むためにも

は、あなたが課金されますあなたがまったく新しいクエリを発行した場合。

これはgetsにも当てはまります:30分以内にgetを繰り返し、変更がない場合は無料です。

この仕組みはFirestoreが最後に指定されたクエリを発行して以来の変更を求めるクエリを含む "resume token"を含んでいるということです。

クライアントがenabling debug loggingによって再開トークンを送信していることを確認できます。サーバー上の変更がない場合は、あなたがよクエリを繰り返したときに

Nov 1 16:44:36 Firestore_Example[8105] <Debug>: [Firebase/Firestore][I-FST000001] FSTWatchStream 0x6080002cbc20 watch: <GCFSListenRequest 0x6180002cc010>: { 
    database: "projects/my-project/databases/(default)" 
    add_target { 
    documents { 
     documents: "projects/my-project/databases/(default)/documents/test-collection/c1GK3eq7rakmRvIN4ehE" 
    } 
    resume_token: "\n\t\010\254\251\304\242\307\236\327\002" 
    target_id: 2 
    } 
} 

:何度もクエリ多くを作るときは、最初に超えたクエリに対して、このようなログの何かに表示されますこの2番目のリクエストを作成したにもかかわらず、応答が実際にドキュメントを転送するわけではなく、単にクライアントが最新であることを示していることに気付くこともできます。

+0

しかし、私の問題は、いくつかの機能を実行するにはブール値が必要です!サーバー側でデータが変更されていない場合でも、 –

+0

データは常に返されます。ドキュメントが変更されておらず、30分以内にリクエストを繰り返す場合、クライアントが最新であることを検証するクエリに対しては料金がかかりません。 –

関連する問題