在本文中,我们将详细介绍遍历Firebase中的快照子级的各个方面,并为您提供关于遍历表字段的相关解答,同时,我们也将为您带来关于android–Firebase电话身份验证凭据链接与firebase
在本文中,我们将详细介绍遍历Firebase中的快照子级的各个方面,并为您提供关于遍历表字段的相关解答,同时,我们也将为您带来关于android – Firebase电话身份验证凭据链接与firebase中的Google登录、android – 无法解决:com.google.firebase:firebase-firestore:11.4.2 [复制]、android-FIrebase Cloud Messaging,无法解析依赖项com.google.firebase:firebase-core:9.0.2、angularjs – 如何遍历Firebase实例的子项的有用知识。
本文目录一览:- 遍历Firebase中的快照子级(遍历表字段)
- android – Firebase电话身份验证凭据链接与firebase中的Google登录
- android – 无法解决:com.google.firebase:firebase-firestore:11.4.2 [复制]
- android-FIrebase Cloud Messaging,无法解析依赖项com.google.firebase:firebase-core:9.0.2
- angularjs – 如何遍历Firebase实例的子项
遍历Firebase中的快照子级(遍历表字段)
我有一个Firebase资源,其中包含几个对象,我想使用Swift对其进行迭代。我期望的工作如下(根据Firebase文档)
https://www.firebase.com/docs/ios-
api/Classes/FDataSnapshot.html#//api/name/children
var ref = Firebase(url:MY_FIREBASE_URL)ref.observeSingleEventOfType(.Value, withBlock: { snapshot in println(snapshot.childrenCount) // I got the expected number of items for rest in snapshot.children { //ERROR: "NSEnumerator" does not have a member named "Generator" println(rest.value) } })
因此,看来Swift遍历Firebase返回的NSEnumerator对象存在问题。
非常欢迎您提供帮助。
答案1
小编典典如果我没看错文档,这就是您想要的:
var ref = Firebase(url: MY_FIREBASE_URL)ref.observeSingleEvent(of: .value) { snapshot in print(snapshot.childrenCount) // I got the expected number of items for rest in snapshot.children.allObjects as! [FIRDataSnapshot] { print(rest.value) }}
更好的方法可能是:
var ref = Firebase(url: MY_FIREBASE_URL)ref.observeSingleEvent(of: .value) { snapshot in print(snapshot.childrenCount) // I got the expected number of items let enumerator = snapshot.children while let rest = enumerator.nextObject() as? FIRDataSnapshot { print(rest.value) }}
第一种方法需要NSEnumerator
返回所有对象的数组,然后可以按通常方式枚举该对象。第二种方法是一次从获取一个对象,这NSEnumerator
可能更有效。
无论哪种情况,要枚举的FIRDataSnapshot
对象都是对象,因此您需要进行强制转换,以便可以访问该value
属性。
使用for-in
循环:
自从Swift 1.2天后写出原始答案以来,该语言就得到了发展。现在可以使用for in
直接与枚举器一起使用的循环以及case let
分配类型:
var ref = Firebase(url: MY_FIREBASE_URL)ref.observeSingleEvent(of: .value) { snapshot in print(snapshot.childrenCount) // I got the expected number of items for case let rest as FIRDataSnapshot in snapshot.children { print(rest.value) }}
android – Firebase电话身份验证凭据链接与firebase中的Google登录
signInWithCredential:failure
com.google.firebase.auth.FirebaseAuthUserCollisionException: An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.
阅读本article.是否与article中提到的问题相同?有没有相同的解决方案..
解决方法
firebaseAuth.getCurrentUser().updatePhoneNumber(credential).addOnCompleteListener(this,new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG,"signInWithCredential:success"); Snackbar.make(findViewById(android.R.id.content),"Mobile Verified Successfully.",Snackbar.LENGTH_SHORT).show(); } else { Log.w(TAG,"signInWithCredential:failure",task.getException()); if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) { //mVerificationField.setError("Invalid code."); Snackbar.make(findViewById(android.R.id.content),"Invalid Code.",Snackbar.LENGTH_SHORT).show(); } else { Toast.makeText(context,"signInWithCredential:failure"+task.getException(),Snackbar.LENGTH_LONG).show(); } } } });
只需将PhoneAuthCredential传递给上述方法,它就会验证手机是否已分配给您现有的帐户.确保任何其他帐户都不使用它.
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId,code);
android – 无法解决:com.google.firebase:firebase-firestore:11.4.2 [复制]
参见英文答案 > Failed to resolve com.google.android.gms play-services-auth:11.4.0 12个
我正在尝试在已经使用Firebase功能的项目中实现新的Firestore数据库,包括实时数据库 – 我想要“升级”.
我正在按照this指南工作,但我在编译Firestore库时遇到困难.
这是我目前的项目gradle:
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我当前的应用程序gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsversion "25.0.2"
defaultConfig {
applicationId "com.tal.wikirace"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
dependencies {
compile filetree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.api-client:google-api-client:1.22.0'
compile'com.google.api-client:google-api-client-android:1.22.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.google.http-client:google-http-client:1.18.0-rc'
compile 'com.android.support:design:25.3.1'
compile 'com.google.android.gms:play-services-auth:11.4.2'
compile 'com.google.firebase:firebase-auth:11.4.2'
compile 'com.google.firebase:firebase-database:11.4.2'
compile 'com.google.firebase:firebase-messaging:11.4.2'
}
apply plugin: 'com.google.gms.google-services'
该项目工作正常,但当我尝试添加此行:
compile 'com.google.firebase:firebase-firestore:11.4.2'
我收到这条消息:
Failed To Resolve: com.google.firebase:firebase-firestore:11.4.2
我更新了Android SDK Build-Tools,Google Play服务和支持存储库,但它没有帮助.
我怎样才能解决这个问题?
解决方法:
你错过了allprojects块中的google maven repo:
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
如果您使用的是Gradle 4.1或更高版本,则可以简化它:
allprojects {
repositories {
jcenter()
google()
}
}
allprojects存储库是用于查找应用程序模块的内容.在buildscript中,它仅为gradle插件定位模块.
此外,您应确保所有Firebase模块具有相同的版本.
android-FIrebase Cloud Messaging,无法解析依赖项com.google.firebase:firebase-core:9.0.2
我试图按照here给出的指南使用Firebase Cloud Messaging编写应用程序,但我为添加实现FCM的依赖项而感到惊讶(com.google.firebase:firebase-core:9.0.2).每次我尝试通过项目结构添加它时,它都不会在搜索结果中列出依赖项.当我尝试将其添加到应用程序级别gradle中时,它给我一个错误,导致无法解决依赖关系.我不知道我要去哪里错了,但是请帮我解决这个问题.
解决方法:
从您的SDK管理器下载更新.我遇到过同样的问题.从SDK经理更新Google Play服务和Google Repository对我来说很有效.
angularjs – 如何遍历Firebase实例的子项
我的firebase对象如下所示:
对我来说它看起来像一本字典,所以从Getting a list of associative array keys开始我试过了
syncData('everyone').$bind($scope,'everyone').then(function() { var keys = $scope.everyone.$getIndex(); for (var key in $scope.everyone) { console.log("key : " + key + " value : " + $scope.everyone[key]); } });
日志确实包含子对象,但它也包含所有方法.像这样
... Before this line is all the other methods. key : $on value : function (a,c){if("loaded"==a&&b._loaded)return b._timeout(function(){c()}),void 0;if(!b._on.hasOwnProperty(a))throw new Error("Invalid event type "+a+" specified");b._on[a].push(c)} controllers.js:58 key : $off value : function (a,c){if(b._on.hasOwnProperty(a))if(c){var d=b._on[a].indexOf(c);-1!==d&&b._on[a].splice(d,1)}else b._on[a]=[];else b._fRef.off()} controllers.js:58 key : $auth value : function (a){var c=b._q.defer();return b._fRef.auth(a,function(a,b){null!==a?c.reject(a):c.resolve(b)},function(a){c.reject(a)}),c.promise} controllers.js:58 key : $getIndex value : function (){return angular.copy(b._index)} controllers.js:58 key : -JH45WOOAtnZfUZkrJb1 value : [object Object] controllers.js:58 key : -JH45YdfwptGv3y6UqyV value : [object Object] controllers.js:58 key : -JH45_zxptV_dmibyGzL value : [object Object]
有没有办法让孩子们得到它?
我之所以这样做是因为我的代码设计用于使用数组,但Firebase不鼓励使用数组(对于多人可能更改的值).所以我试图遍历firebase字典并将对象复制到客户端的数组中.所以我不必改变太多的代码.
在angularFire对象中迭代值的正确方法是使用$getIndex().你在上面的代码中有这个,但没有在for循环中使用它.
由于您已经在使用angularFire lib(syncData是使用angularFire的angularFire-seed服务),因此无需担心调用$apply()或将数据哄骗到Angular中的任何其他复杂性(详见上一个答案)对原始Firebase / Angular实施的良好响应).
相反,只需更改for循环以迭代键而不是angularFire实例:
syncData('everyone').$bind($scope,'everyone').then(function() { var keys = $scope.everyone.$getIndex(); // utilizing Angular's helpers angular.forEach(keys,function(key) { console.log(key,$scope.everyone[key]); }); // or as a for loop for(var i=0,len = keys.length; i < len; i++) { console.log(keys[i],$scope.everyone[keys[i]]); } });
要使用DOM中的对象,请使用ng-repeat:
<ul> <li ng-repeat="(key,user) in everyone">{{key}},{{user|json}}</li> </ul>
今天关于遍历Firebase中的快照子级和遍历表字段的讲解已经结束,谢谢您的阅读,如果想了解更多关于android – Firebase电话身份验证凭据链接与firebase中的Google登录、android – 无法解决:com.google.firebase:firebase-firestore:11.4.2 [复制]、android-FIrebase Cloud Messaging,无法解析依赖项com.google.firebase:firebase-core:9.0.2、angularjs – 如何遍历Firebase实例的子项的相关知识,请在本站搜索。
本文标签: