带有Firebase的Cordova无法正常工作

先生。自己

我正在使用Cordova和Firebase创建应用程序。

我已完成的众多功能之一是该功能:

function searchForGameRound() {
var ref = new Firebase("https://grootproject.firebaseio.com/Users/");

// Dit is de query naar Firebase toe (kan je vergelijken met een query als bij SQL)
var query = ref.orderByChild("gameSearching").equalTo(true);
console.log('spelen');

// Hierbij geef ik aan dat hij dit enkel 1x mag doen. Dit voorkomt dat hij dit op elk child gaat uitvoeren (wat meerdere games maakt).
query.once("value", function (data) {
    console.log('spelen', data.val());

    if (data.val() === null) {
        updateData(('Users/' + you + '/'), {gameSearching: true});
        return;
    }
    var alreadyInCurrentGame;

    var object = data.val();
    var user1 = Object.keys(object)[0];
    var user2 = Object.keys(object)[1];

    // Als je het zelf bent
    if (you == user1) {
        if (user2) {
            opponent = user2;
        } else {
            updateData(('Users/' + you + '/'), {gameSearching: true});
            return;
        }
    } else {
        opponent = user1;
    }

    console.log(opponent, 'opponent found');

    // Hierbij gaat hij kijken of er al een currentgame bestaat met deze user
    var ref = new Firebase('https://grootproject.firebaseio.com/Users/' + you + '/currentGames/' + opponent + '/');
    ref.once("value", function (snapshot) {
        if (!snapshot.val() === null) {
            console.log(snapshot.val(), ' bestaat al');
            alreadyInCurrentGame = true;
        }
    }, function (errorObject) {
        console.log(errorObject.error);
    });

    // Als alles goed is, gooit hij er data in.
    if (!alreadyInCurrentGame) {
        console.log('spel gevonden');


        var game = new Firebase("https://grootproject.firebaseio.com/Games/");
        game.on("value", function (data) {

            var length = Object.keys(data.val()).length;

            for (var i = 0; i < length; i++) {
                games.push(Object.keys(data.val())[i]);
            }

            game1 = Math.floor(Math.random() * 4);
            game2 = Math.floor(Math.random() * 4);
            game3 = Math.floor(Math.random() * 4);

            while(game1 == game2){
                game2 = Math.floor(Math.random() * 4);
            }

            while(game2 == game3){
                game3 = Math.floor(Math.random() * 4);
            }

            console.log(games, 'games');
            game1 = games[game1];
            game2 = games[game2];
            game3 = games[game3];
            console.log(game1);
            console.log(game2);
            console.log(game3);

            var url = 'https://grootproject.firebaseio.com/Users/' + opponent + '/currentGames/' + you + '/';
            var fir = new Firebase(url);
            fir.set(
                {

                    round1: {score: '-', game: game1},
                    round2: {score: '-', game: game2},
                    round3: {score: '-', game: game3}
                }
            );

            url = 'https://grootproject.firebaseio.com/Users/' + you + '/currentGames/' + opponent + '/';
            fir = new Firebase(url);
            fir.set(
                {
                    round1: {score: '-', game: game1},
                    round2: {score: '-', game: game2},
                    round3: {score: '-', game: game3}
                }
            );

            url = 'https://grootproject.firebaseio.com/Users/' + you + '/';
            fir = new Firebase(url);
            fir.update(
                {gameSearching: false}
            );

            console.log(opponent, ' opponent');
            url = 'https://grootproject.firebaseio.com/Users/' + opponent + '/';
            fir = new Firebase(url);
            fir.update(
                {gameSearching: false}
            );
        });

    } else {
        updateData(('Users/' + you + '/'), {gameSearching: true});
    }
}, function (err) {
    console.log(err, 'error');
});

}

我的Firebase规则:

{
  "rules": {
    ".read": true,
    ".write": true,
    "Users": {
      ".indexOn": "gameSearching"
    }
  }
}

似乎当他使用Firebase时,console.logs不会显示(该功能也不会起作用)。

我得到的唯一console.log是第一个console.log('spelen')对我来说奇怪的是,在我的电脑上,它可以正常工作。

并非只有该功能无法正常运行。每次我使用Firebase在手机上检索一些数据时,它将无法正常工作。

我正在使用最新版本的Cordova和Firebase版本2.0.4

任何的想法?


编辑

它似乎仅在我登录该应用程序时有效。当我已经登录到firebase(firebase.getAuth())时,该功能将无法正常工作,并且我也不会从firebase中检索任何数据。

先生。自己

如果不使用功能authWithPassword或unauth,firebase似乎无法建立任何连接。

我通过使用Firebase.goOnline()解决了我的问题每当应用程序启动时;

document.addEventListener("deviceready", function () { 
    Firebase.goOnline();
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

带有Firebase的Cordova无法正常工作

来自分类Dev

带有Cordova的iOS上的jQuery .text()无法正常工作

来自分类Dev

带有Firebase的Android Studio无法正常工作

来自分类Dev

带有ajax的addeventlistener无法正常工作

来自分类Dev

带有字幕的TextView无法正常工作

来自分类Dev

带有addPreferencesFromResource的AppCompatPreferenceActivity无法正常工作

来自分类Dev

带有Lastrow的FormulaArray无法正常工作

来自分类Dev

带有uiPageViewControllers的SetViewControllers无法正常工作

来自分类Dev

带有SliverAppBar的ScrollablePositionedList无法正常工作

来自分类Dev

带有确认的Socketclustser无法正常工作

来自分类Dev

带有AJAX的fancybox无法正常工作

来自分类Dev

带有bxslider的Colorbox无法正常工作

来自分类Dev

带有getIdentifier的findViewById无法正常工作

来自分类Dev

带有jsp的Servlet无法正常工作

来自分类Dev

带有archiveRootObject的URLByAppendingPathComponent无法正常工作?

来自分类Dev

带有灰度的imagemagick无法正常工作

来自分类Dev

带有uiPageViewControllers的SetViewControllers无法正常工作

来自分类Dev

Firebase无法正常工作

来自分类Dev

Firebase 无法正常工作

来自分类Dev

带有ng-if的ngTable无法正常工作

来自分类Dev

带有Interactive Brokers API的Ibpy无法正常工作

来自分类Dev

带有市场的Admin-SDK无法正常工作

来自分类Dev

Angular中带有$ http的HTTPS无法正常工作

来自分类Dev

为什么带有AJAX的rspec示例无法正常工作?

来自分类Dev

带有关键路径“界限”的CABasicAnimation无法正常工作

来自分类Dev

带有HTML的Ejs引擎无法正常工作

来自分类Dev

带有Views参数的Ajax Quicktab无法正常工作

来自分类Dev

带有AllowColumnReorder的ListView OwnerDraw无法正常工作

来自分类Dev

带有node.js的cloudinary作物无法正常工作?

Related 相关文章

  1. 1

    带有Firebase的Cordova无法正常工作

  2. 2

    带有Cordova的iOS上的jQuery .text()无法正常工作

  3. 3

    带有Firebase的Android Studio无法正常工作

  4. 4

    带有ajax的addeventlistener无法正常工作

  5. 5

    带有字幕的TextView无法正常工作

  6. 6

    带有addPreferencesFromResource的AppCompatPreferenceActivity无法正常工作

  7. 7

    带有Lastrow的FormulaArray无法正常工作

  8. 8

    带有uiPageViewControllers的SetViewControllers无法正常工作

  9. 9

    带有SliverAppBar的ScrollablePositionedList无法正常工作

  10. 10

    带有确认的Socketclustser无法正常工作

  11. 11

    带有AJAX的fancybox无法正常工作

  12. 12

    带有bxslider的Colorbox无法正常工作

  13. 13

    带有getIdentifier的findViewById无法正常工作

  14. 14

    带有jsp的Servlet无法正常工作

  15. 15

    带有archiveRootObject的URLByAppendingPathComponent无法正常工作?

  16. 16

    带有灰度的imagemagick无法正常工作

  17. 17

    带有uiPageViewControllers的SetViewControllers无法正常工作

  18. 18

    Firebase无法正常工作

  19. 19

    Firebase 无法正常工作

  20. 20

    带有ng-if的ngTable无法正常工作

  21. 21

    带有Interactive Brokers API的Ibpy无法正常工作

  22. 22

    带有市场的Admin-SDK无法正常工作

  23. 23

    Angular中带有$ http的HTTPS无法正常工作

  24. 24

    为什么带有AJAX的rspec示例无法正常工作?

  25. 25

    带有关键路径“界限”的CABasicAnimation无法正常工作

  26. 26

    带有HTML的Ejs引擎无法正常工作

  27. 27

    带有Views参数的Ajax Quicktab无法正常工作

  28. 28

    带有AllowColumnReorder的ListView OwnerDraw无法正常工作

  29. 29

    带有node.js的cloudinary作物无法正常工作?

热门标签

归档