2016-10-14 17 views
0

Ayyyy、仲間! Firebaseにオブジェクトに追加された新しい子供の量を得る方法があるかどうか疑問に思っていました。これを行うためにとにかくありますか?もしあれば教えてください!新しい通知の受信数を取得する方法

新しいオブジェクトがオブジェクトのグループに追加された場合、私はより論理的にはどういう意味ですか?上記添付画像で

User object

、私は上記の[通知]ノードに追加された新要素の量を取得しようとしています。

私の試み:

FIRDatabase.database().reference().child("users").child(self.uid!).child("notifications").observe(.childAdded, with: { (snapshot) in 

      let amountOfNotifications = snapshot.childrenCount 

     }) 

JSON:

{ 
    "email" : "[email protected]", 
    "followers" : { 
    "alsdkf" : "[email protected]", 
    "asdfasdf" : "ljfklasdjl;[email protected]:KJl;kaf.daisodf", 
    "asdfasdfk" : ";lkjaksldjfkl;[email protected];lkjlka;jdf.omc", 
    "dgsddfaf" : "lk;[email protected];ajdlkfa.io", 
    "follower1" : "[email protected]", 
    "follower10z" : "[email protected]", 
    "follower2" : "[email protected]", 
    "follower3" : "[email protected]", 
    "follower4" : "l;kajsfkljasdflk;[email protected]:Jlkajdsfl;kasdf.oio", 
    "follower7" : "[email protected]", 
    "followerte" : "[email protected]", 
    "folower8" : "zed>[email protected]", 
    "test" : "[email protected]" 
    }, 
    "name" : "ASDFASDF", 
    "notifications" : { 
    "let notification 1343936250 = new follower" : "Optional(lk;[email protected];ajdlkfa.io) followed you!", 
    "let notification 1588601033 = new follower" : "Optional(;lkjaksldjfkl;[email protected];lkjlka;jdf.omc) followed you!", 
    "let notification 1644747852 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 1680115082 = new follower" : "Optional(l;kajsfkljasdflk;[email protected]:Jlkajdsfl;kasdf.oio) followed you!", 
    "let notification 1730793657 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 1820028610 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 1975523553 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 2129596138 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 2181363532 = new follower" : "Optional(;lkjaksldjfkl;[email protected];lkjlka;jdf.omc) followed you!", 
    "let notification 2367950713 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 2409722982 = new follower" : "Optional(;lkjaksldjfkl;[email protected];lkjlka;jdf.omc) followed you!", 
    "let notification 2431788206 = new follower" : "Optional(zed>[email protected]) followed you!", 
    "let notification 2469280631 = new follower" : "Optional(ljfklasdjl;[email protected]:KJl;kaf.daisodf) followed you!", 
    "let notification 2750686409 = new follower" : "Optional(l;kajsfkljasdflk;[email protected]:Jlkajdsfl;kasdf.oio) followed you!", 
    "let notification 2800426934 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 2835016479 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 2914050639 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 2954110099 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 2963247743 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 3251218202 = new follower" : "Optional(zed>[email protected]) followed you!", 
    "let notification 340385741 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 3424214838 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 3491288550 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 3734762074 = new follower" : "Optional(ljfklasdjl;[email protected]:KJl;kaf.daisodf) followed you!", 
    "let notification 3788313156 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 3862281533 = new follower" : "Optional(l;kajsfkljasdflk;[email protected]:Jlkajdsfl;kasdf.oio) followed you!", 
    "let notification 3863677856 = new follower" : "Optional(lk;[email protected];ajdlkfa.io) followed you!", 
    "let notification 3867733078 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 3942761365 = new follower" : "Optional(lk;[email protected];ajdlkfa.io) followed you!", 
    "let notification 4066943532 = new follower" : "Optional(ljfklasdjl;[email protected]:KJl;kaf.daisodf) followed you!", 
    "let notification 4083932515 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 509688728 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 599767405 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 745520426 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 882753091 = new follower" : "Optional([email protected]) followed you!", 
    "let notification 937740183 = new follower" : "Optional(zed>[email protected]) followed you!", 
    "let notification = new follower" : "Optional([email protected]) followed you!", 
    "not" : "test", 
    "notification1" : "Welcome to platform!", 
    "notification2" : "someIdiotFollowedYou!", 
    "notification3" : "test", 
    "testNot" : "alksdjf;klajsdf", 
    "testNoti" : "test" 
    }, 
    "peopleFollowing" : { 
    "following1" : "[email protected]", 
    "following2" : "[email protected]" 
    }, 
    "profileImageUrl" : "https://firebasestorage.googleapis.com/v0/b/platform-ad9e3.appspot.com/o/profile_images%2FprofileImageRIjJxqqyVdVnwqpB507SRkl2Zhf1.jpeg?alt=media&token=ea86df9e-4949-4409-b92d-3ed8db64f5de", 
    "rank" : "Laksjdfklja;add", 
    "userid" : "RIjJxqqyVdVnwqpB507SRkl2Zhf1" 
} 
+0

* new children *は相対用語ですが、それはどういう意味ですか? – Dravidian

+0

私はJSONツリー構造を** text **スニペットではないと言っていたので、ダッシュボードに移動し、ダッシュボードの右上にある3つの点をクリックしてJSONをエクスポートし、 (通知の中) – Dravidian

答えて

2

私は、ユーザーがその通知を確認するためにクリックする必要があり、彼はあなたをクリックするたびに、クエリ検索を送ることそのボタンを想定していますそれのための。

noOfFollwersWhenLastChecked値でnotificationノードとsubstractであったノードの一切を数え、あなたのJSONの構造上

{ 
    "email" : "[email protected]", 
    "followers" : {...}, 
    "name" : "ASDFASDF", 
    "notifications" : {...}, 
    "peopleFollowing" : {...}, 
    "noOfFollwersWhenLastChecked" : 100, // 
    "profileImageUrl" : 
    "userid" : "RIjJxqqyVdVnwqpB507SRkl2Zhf1" 
    } 

たびに、ユーザーのアクセスnotificationsノードを別のノードを維持していないし、カウントしてその値を置き換えますノードの番号はnotificationにあります。

+0

ありがとう!出来た! – KawaiiFX

+0

ユーザーがnotificationsViewControllerを離れるときに、すべての値が削除されるようにすることもできませんでしたか? – KawaiiFX

関連する問題