从Ionic应用程序连接到firebase 3时出错

时间:2016-08-11 02:06:57

标签: angularjs ionic-framework firebase firebase-realtime-database firebase-authentication

尝试从Ionic应用程序连接到firebase 3时出错。该应用程序运行良好,新的v3配置等都很好,我确定代码很好,但我只是在下面添加它。

我认为这是我的firebase设置,Signin方法Email/Passwordenabled。我是否需要ios应用程序建议的plist文件?说明令人困惑,因为没有特定的离子指令,只有ios,android和web。

有关如何前进的任何建议? (谷歌似乎已经做了一些非常复杂的事情,之前更简单:()

谢谢。

这是我的连接错误(有没有办法获得比这更好的错误?):

code: "auth/network-request-failed", message: "A network error (such as timeout, interrupted connection or unreachable host) has occurred."}
code
:
"auth/network-request-failed"
message
:
"A network error (such as timeout, interrupted connection or unreachable host) has occurred."

这是我在index.html中的配置数据

<script>
// Initialize Firebase
var config = {
    apiKey: "myapikeymyapikeymyapikey",
    authDomain: "myapp.firebaseapp.com",
    databaseURL: "https://myapp.firebaseio.com",
    storageBucket: "myapp.appspot.com",
};
firebase.initializeApp(config);

这是应用中的firebase代码:

.factory('userService', function($rootScope, $window, $timeout, firebaseDBRef, firebaseAuthRef, firebaseUserRef, myStocksArrayService, myStocksCacheService, notesCacheService, modalService) {

  var login = function(user, signup) {
    var email = user.email;
    var password = user.password;

    firebaseAuthRef.signInWithEmailAndPassword(email, password)
      .then(function() {
        $rootScope.currentUser = authData;

        if(signup) {
          modalService.closeModal();
        }
        else {
          myStocksCacheService.removeAll();
          notesCacheService.removeAll();

          loadUserData(authData);

          modalService.closeModal();
          $timeout(function() {
            $window.location.reload(true);
          }, 400);
        }
      })
      .catch(function(error) {
        console.log("Login Failed!", error);
        return false;
      });
  };

  var signup = function(user) {

    firebaseAuthRef.createUserWithEmailAndPassword(user.email, user.password)
    .then(function(userData) {
      console.log(userData);
      login(user, true);
      firebaseDBRef.child('emails').push(user.email);
      firebaseUserRef.child(userData.uid).child('stocks').set(myStocksArrayService);

      var stocksWithNotes = notesCacheService.keys();

      stocksWithNotes.forEach(function(stockWithNotes) {
        var notes = notesCacheService.get(stockWithNotes);

        notes.forEach(function(note) {
          firebaseUserRef.child(userData.uid).child('notes').child(note.ticker).push(note);
        });
      });
    })
    .catch(function(error) {
      console.log("Error creating user:", error);
      return false;
    });
  };

  var logout = function() {
    firebaseAuthRef.signOut();
    notesCacheService.removeAll();
    myStocksCacheService.removeAll();
    $window.location.reload(true);
    $rootScope.currentUser = '';
  };

  var updateStocks = function(stocks) {
    firebaseUserRef.child(getUser().uid).child('stocks').set(stocks);
  };

  var updateNotes = function(ticker, notes) {
    firebaseUserRef.child(getUser().uid).child('notes').child(ticker).remove();
    notes.forEach(function(note) {
      firebaseUserRef.child(getUser().uid).child('notes').child(note.ticker).push(note);
    });
  };

  var loadUserData = function(authData) {

    firebaseUserRef.child(authData.uid).child('stocks').once('value', function(snapshot) {
      var stocksFromDatabase = [];

      snapshot.val().forEach(function(stock) {
        var stockToAdd = {ticker: stock.ticker};
        stocksFromDatabase.push(stockToAdd);
      });

      myStocksCacheService.put('myStocks', stocksFromDatabase);
    },
    function(error) {
      console.log("Firebase error –> stocks" + error);
    });

    firebaseUserRef.child(authData.uid).child('notes').once('value', function(snapshot) {

      snapshot.forEach(function(stocksWithNotes) {
        var notesFromDatabase = [];
        stocksWithNotes.forEach(function(note) {
          notesFromDatabase.push(note.val());
          var cacheKey = note.child('ticker').val();
          notesCacheService.put(cacheKey, notesFromDatabase);
        });
      });
    },
    function(error) {
      console.log("Firebase error –> notes: " + error);
    });
  };

  var getUser = function() {
    return firebaseAuthRef.currentUser;
  };

  if(getUser()) {
    $rootScope.currentUser = getUser();
  }

  return {
    login: login,
    signup: signup,
    logout: logout,
    updateStocks: updateStocks,
    updateNotes: updateNotes,
    getUser: getUser
  };
})

1 个答案:

答案 0 :(得分:1)

你必须添加plist!不,你已经拥有它了吗?!

its a file that will be downloaded when you add your app to firebase

然后你必须将它添加到你的应用程序:

you have to add it to your app

请注意;如果您下载的次数超过一次,则会显示数字(2)或(3)或(4),因此请在xcode中删除这些数字,文件名应为GoogleService-Info.plist。如果它是其他任何东西,它就不会起作用。